package io.renren.socket;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.netty.channel.ChannelHandlerContext;
import io.renren.common.utils.Constant;
import io.renren.modules.substation.entity.*;
import io.renren.modules.substation.service.TSampAeDataInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class UploadSampData {

    public static Logger logger = LoggerFactory.getLogger(UploadSampData.class);

    //终端上传局放实时视频数据
    public static void uploadJfStream(ServerHandler serverHandler,JSONObject q_obj,JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
//            String result = obj.getString("result");
            String msgId = obj.getString("msgId");
//
//            result.equals("ok");
//            msg.equals("成功");
//            result.equals("error");
//            msg.equals("设备忙，失败");
            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject JfVideoStreamDataobj = contentobj.getJSONObject("JfVideoStreamData");

            String devSrc = JfVideoStreamDataobj.getString("devSrc");
            String purpose = JfVideoStreamDataobj.getString("purpose");
            String devId = JfVideoStreamDataobj.getString("devId");
            String arrayType = JfVideoStreamDataobj.getString("arrayType");
            String ePhase = JfVideoStreamDataobj.getString("ePhase");
            String eFreq = JfVideoStreamDataobj.getString("eFreq");
            String array = JfVideoStreamDataobj.getString("array");
            //入库或更新操作

            SendMsgRes.sendJsonResMsgOKorERROR("uploadJfStreamRsp",Constant.CMD_OK,null,q_obj,null,null,ctx);
//            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("uploadJfStream error： " + ex);
        }
//        "action": "uploadJfStream",
//                "msgId":"",
//                "content": {
//            "JfVideoStreamData": {
//                "devSrc": "dev",
//                        "purpose": "jfVideoStream",
//                        "devId": "TP01MN2181221000042",
//                        "arrayType": "double",
//                        "ePhase": "60",
//                        "eFreq": "50",
//                        "array": "123.1,23.1,78.0,109.7,xxx,145.0"
//            }
//        }
//        devId 文件来源设备 ID String 可选 终端自身数据，可以留空；
//        IED 通道（SU10）数据填入
//        其 ID 号（SU10 SN 号）
//        ePhase 相位窗数 String 必备 每周期采样个数
//        eFreq 工频周期数 String 必备 本次数据包含周期个数
//        arrayType 数组元素类型 String 必备 见附录定义 附录数组类型 arrayType
//                定义
//        array 数组内容 String 必备 Array.length=ePhase*eFreq 数组用,拼接
    }

    //终端上传声音传感器采样数据
    public static void uploadSampleDataSound(ServerHandler serverHandler,JSONObject q_obj,JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("uploadSampleDataSound");
        try {
//            String msgId = obj.getString("msgId");

            TBusiDevStatusInfoEntity tBusiDevStatusInfoEntity = new TBusiDevStatusInfoEntity();
            TSampBasiDataInfoEntity tSampBasiDataInfoEntity = new TSampBasiDataInfoEntity();

            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject SoundSampleDataobj = contentobj.getJSONObject("SoundSampleData");
            JSONObject SampleDataBaseobj = SoundSampleDataobj.getJSONObject("SampleDataBase");
            String devSrc = SampleDataBaseobj.getString("devSrc");
            String devId = SampleDataBaseobj.getString("devId");
            String module = SampleDataBaseobj.getString("module");
            String time = SampleDataBaseobj.getString("time");
            String state = SampleDataBaseobj.getString("state");
            JSONObject ExceptionInfoobj = SampleDataBaseobj.getJSONObject("ExceptionInfo");
            if(ExceptionInfoobj != null) {
                String type = ExceptionInfoobj.getString("type");
                String msg = ExceptionInfoobj.getString("msg");
                tSampBasiDataInfoEntity.setSampExceptionType(type);
                tSampBasiDataInfoEntity.setSampExceptionMsg(msg);
            }

            time = dateTimeToString(time);

            TBusiDevMonitorInfoEntity tBusiDevMonitorInfoEntity = new TBusiDevMonitorInfoEntity();
            tBusiDevMonitorInfoEntity.setLastOpr((long)0);
            tBusiDevMonitorInfoEntity.setLastTime(new Date());
            tBusiDevMonitorInfoEntity.setDevCode(devId);
            tBusiDevMonitorInfoEntity.setMonitorTime(time);
            if(state.equals("warning")){
                tBusiDevStatusInfoEntity.setDevCode(devId);
                tBusiDevStatusInfoEntity.setIsAlarm("1");
                tBusiDevStatusInfoEntity.setLastOpr((long)0);
                tBusiDevStatusInfoEntity.setLastTime(new Date());

                int upsum = serverHandler.tBusiDevStatusInfoService.updateDevStatusInfoByCode(tBusiDevStatusInfoEntity);
                if(upsum <= 0) {
                    logger.debug("插入新数据 uploadSampleDataSound tBusiDevStatusInfoEntity");
                    tBusiDevStatusInfoEntity.setCreateTime(new Date());
                    tBusiDevStatusInfoEntity.setCreateOpr((long)0);
                    tBusiDevStatusInfoEntity.setDevStatus("1");
                    tBusiDevStatusInfoEntity.setIsVaild("1");
//                    serverHandler.tBusiDevStatusInfoService.save(tBusiDevStatusInfoEntity);
                }

                tBusiDevMonitorInfoEntity.setVariableKind("00");
                tBusiDevMonitorInfoEntity.setVariableDesc("噪声");
                tBusiDevMonitorInfoEntity.setVariableStatus("1");

                Date t = new Date();
                SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                int resultal = serverHandler.tBusiSysAlarmInfoService.insertAlarmInfoBySystem(df.format(t), tBusiDevMonitorInfoEntity.getDevCode(), "00" + tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableDesc() + "告警");
                logger.debug("噪声插入告警：编号[" + tBusiDevMonitorInfoEntity.getDevCode() + "]值：" + resultal);


            }else{

//                TBusiDevMonitorInfoEntity tBusiDevMonitorInfoEntity = new TBusiDevMonitorInfoEntity();
//                tBusiDevMonitorInfoEntity.setLastOpr((long)0);
//                tBusiDevMonitorInfoEntity.setLastTime(new Date());
//                tBusiDevMonitorInfoEntity.setDevCode(devId);

                tBusiDevMonitorInfoEntity.setVariableKind("00");
                tBusiDevMonitorInfoEntity.setVariableDesc("噪声");
                tBusiDevMonitorInfoEntity.setVariableStatus("0");
//                serverHandler.tBusiDevMonitorInfoService.updateMonitorByCodeKindDesc(tBusiDevMonitorInfoEntity);
            }

            int upsum2 = serverHandler.tBusiDevMonitorInfoService.updateMonitorByCodeKindDesc(tBusiDevMonitorInfoEntity);
            if(upsum2 <= 0) {
                logger.debug("更新噪声状态不存在 updateMonitorByCodeKindDesc-插入");

                tBusiDevMonitorInfoEntity.setCreateTime(new Date());
                tBusiDevMonitorInfoEntity.setCreateOpr((long)0);
                tBusiDevMonitorInfoEntity.setVariableValue("0");
                tBusiDevMonitorInfoEntity.setVariableValue2("0");
                tBusiDevMonitorInfoEntity.setVariableValue3("0");
                try {
                    String codeStr = getVariableCodeByName(tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableKind(), serverHandler);
                    if (codeStr != null && codeStr != "") {
                        tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                    } else {
                        tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                        logger.debug("code值未配置：name:" + tBusiDevMonitorInfoEntity.getVariableDesc() + " kind:" + tBusiDevMonitorInfoEntity.getVariableKind());
                    }

                    serverHandler.tBusiDevMonitorInfoService.save(tBusiDevMonitorInfoEntity);
                }catch(Exception e){
                    logger.debug("monitor 添加失败:噪声");
                }
            }

            tSampBasiDataInfoEntity.setDevSrc(devSrc);
            tSampBasiDataInfoEntity.setDevId(devId);
            tSampBasiDataInfoEntity.setModuleName(module);
            tSampBasiDataInfoEntity.setSampTime(time);
            tSampBasiDataInfoEntity.setSampState(state);
            tSampBasiDataInfoEntity.setCreateTime(new Date());
            tSampBasiDataInfoEntity.setLastTime(new Date());

            boolean saveflag;
            logger.debug("保存数据库------");
            int updsum = serverHandler.tSampBasiDataInfoService.updateSampValueByDevData(tSampBasiDataInfoEntity);
            if(updsum <= 0) {
                logger.debug("插入新数据 uploadSampleDataSoundRsp tSampBasiDataInfoEntity");
                saveflag = serverHandler.tSampBasiDataInfoService.save(tSampBasiDataInfoEntity);
                if (!saveflag) {
                    logger.error("保存数据库失败 uploadSampleDataSoundRsp tSampBasiDataInfoEntity");
                    SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataSoundRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                    return;
                }
            }

            String maxSound = SoundSampleDataobj.getString("maxSound");
            String fileSound = SoundSampleDataobj.getString("fileSound");
            String fileWaveform = SoundSampleDataobj.getString("fileWaveform");
            //入库或更新操作
            TSampSoundInfoEntity tSampSoundInfoEntity = new TSampSoundInfoEntity();
            tSampSoundInfoEntity.setDevId(devId);
//                    tSampTevDataInfoEntity.setDevIp(devIp);
            tSampSoundInfoEntity.setMaxSound(maxSound);
            tSampSoundInfoEntity.setFileSound(fileSound);
            tSampSoundInfoEntity.setFileWaveForm(fileWaveform);
            tSampSoundInfoEntity.setCreateTime(new Date());
            tSampSoundInfoEntity.setLastTime(new Date());
            upsum2 = serverHandler.tSampSoundInfoService.updateByDevId(tSampSoundInfoEntity);
            if (upsum2 <= 0) {
                logger.debug("无更新数据-插入新数据 tSampSoundInfoEntity");
                serverHandler.tSampSoundInfoService.save(tSampSoundInfoEntity);
            }
            logger.debug("入历史数据 tSampSoundInfoHisService");
            TSampSoundInfoHisEntity tSampSoundInfoHisEntity = new TSampSoundInfoHisEntity();
            BeanUtils.copyProperties(tSampSoundInfoEntity, tSampSoundInfoHisEntity);
            serverHandler.tSampSoundInfoHisService.save(tSampSoundInfoHisEntity);

            SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataSoundRsp", Constant.CMD_OK, null, q_obj, null, null, ctx);

        } catch (Exception ex) {
            logger.error("uploadSampleDataSound error： " + ex);
        }
//        "action": "uploadSampleDataSound",
//                "msgId": "",
//                "content": {
//            "SoundSampleData": {
//                "SampleDataBase": {
//                    "devSrc": "ied",
//                            "devId": "SU10AX123450007",
//                            "module": "Sound",
//                            "time": "2019-08-22 08:17:58",
//                            "state": "normal",
//                            "ExceptionInfo": {
//                        "type": "1",
//                                "msg": "88%"
//                    }
//                },
//                "fileSound": "20190629_100013_511_sound.wav"
//            }
//        }
    }

    //终端上传暂态地电压采样数据
    public static void uploadSampleDataTev(ServerHandler serverHandler,JSONObject q_obj,JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("uploadSampleDataTev");
        try {
//            String msgId = obj.getString("msgId");

            TBusiDevStatusInfoEntity tBusiDevStatusInfoEntity = new TBusiDevStatusInfoEntity();
            TSampBasiDataInfoEntity tSampBasiDataInfoEntity = new TSampBasiDataInfoEntity();

            JSONObject contentobj = obj.getJSONObject("content");
            if(contentobj != null) {
                JSONObject TevSampleDataobj = contentobj.getJSONObject("TevSampleData");
                if(TevSampleDataobj != null) {
                    JSONObject SampleDataBaseobj = TevSampleDataobj.getJSONObject("SampleDataBase");
                    String devSrc = SampleDataBaseobj.getString("devSrc");
                    String devId = SampleDataBaseobj.getString("devId");
                    String module = SampleDataBaseobj.getString("module");
                    String time = SampleDataBaseobj.getString("time");
                    String state = SampleDataBaseobj.getString("state");
                    JSONObject ExceptionInfoobj = SampleDataBaseobj.getJSONObject("ExceptionInfo");
                    if (ExceptionInfoobj != null) {
                        String type = ExceptionInfoobj.getString("type");
                        String msg = ExceptionInfoobj.getString("msg");
                        tSampBasiDataInfoEntity.setSampExceptionType(type);
                        tSampBasiDataInfoEntity.setSampExceptionMsg(msg);
                    }

                    JSONArray noiseBasearray = TevSampleDataobj.getJSONArray("noiseBase");
                    if (noiseBasearray != null) {
                        for (int i = 0; i < noiseBasearray.size(); i++) {
                            JSONObject noiseBaseobj = noiseBasearray.getJSONObject(i);
                            String noiseBaseName = noiseBaseobj.getString("name");
                            String noiseBaseNB = noiseBaseobj.getString("nb");
                            String noiseBaseUnit = noiseBaseobj.getString("unit");
                            String measureType = noiseBaseobj.getString("measureType");
//                            String noiseBaseUnit = noiseBaseobj.getString("MeasureType");

                            TSampNoiseBaseInfoEntity tSampNoiseBaseInfoEntity = new TSampNoiseBaseInfoEntity();
                            tSampNoiseBaseInfoEntity.setDevSrc(devSrc);
                            tSampNoiseBaseInfoEntity.setDevId(devId);
                            tSampNoiseBaseInfoEntity.setModule(module);
                            tSampNoiseBaseInfoEntity.setMeasureType(measureType);
                            tSampNoiseBaseInfoEntity.setName(noiseBaseName);
                            tSampNoiseBaseInfoEntity.setNb(noiseBaseNB);
                            tSampNoiseBaseInfoEntity.setUnit(noiseBaseUnit);
                            tSampNoiseBaseInfoEntity.setCreateTime(new Date());
                            tSampNoiseBaseInfoEntity.setLastTime(new Date());

                            int upsum = serverHandler.tSampNoiseBaseInfoService.updateNoiseValueByDevData(tSampNoiseBaseInfoEntity);
                            if (upsum <= 0) {
                                logger.debug("无更新数据-插入新数据 tSampNoiseBaseInfoService");
                                serverHandler.tSampNoiseBaseInfoService.save(tSampNoiseBaseInfoEntity);
                            }
                            logger.debug("入历史数据 tSampNoiseBaseInfoHisService");
                            TSampNoiseBaseInfoHisEntity tSampNoiseBaseInfoHisEntity = new TSampNoiseBaseInfoHisEntity();
                            BeanUtils.copyProperties(tSampNoiseBaseInfoEntity, tSampNoiseBaseInfoHisEntity);
                            serverHandler.tSampNoiseBaseInfoHisService.save(tSampNoiseBaseInfoHisEntity);
                        }
                    }

                    time = dateTimeToString(time);

                    TBusiDevMonitorInfoEntity tBusiDevMonitorInfoEntity = new TBusiDevMonitorInfoEntity();
                    tBusiDevMonitorInfoEntity.setLastOpr((long) 0);
                    tBusiDevMonitorInfoEntity.setLastTime(new Date());
                    tBusiDevMonitorInfoEntity.setDevCode(devId);
                    tBusiDevMonitorInfoEntity.setMonitorTime(time);
                    if (state.equals("warning")) {
                        tBusiDevStatusInfoEntity.setDevCode(devId);
                        tBusiDevStatusInfoEntity.setIsAlarm("1");
                        tBusiDevStatusInfoEntity.setLastOpr((long) 0);
                        tBusiDevStatusInfoEntity.setLastTime(new Date());

                        int upsum = serverHandler.tBusiDevStatusInfoService.updateDevStatusInfoByCode(tBusiDevStatusInfoEntity);
                        if (upsum <= 0) {
                            logger.debug("插入新数据 uploadSampleDataSound tBusiDevStatusInfoEntity");
                            tBusiDevStatusInfoEntity.setCreateTime(new Date());
                            tBusiDevStatusInfoEntity.setCreateOpr((long) 0);
                            tBusiDevStatusInfoEntity.setDevStatus("1");
                            tBusiDevStatusInfoEntity.setIsVaild("1");
//                    serverHandler.tBusiDevStatusInfoService.save(tBusiDevStatusInfoEntity);
                        }

                        tBusiDevMonitorInfoEntity.setVariableKind("00");
                        tBusiDevMonitorInfoEntity.setVariableDesc("暂态地电压");
                        tBusiDevMonitorInfoEntity.setVariableStatus("1");

                        Date t = new Date();
                        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                        int resultal = serverHandler.tBusiSysAlarmInfoService.insertAlarmInfoBySystem(df.format(t), tBusiDevMonitorInfoEntity.getDevCode(), "00" + tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableDesc() + "告警");
                        logger.debug("暂态地电压插入告警：编号[" + tBusiDevMonitorInfoEntity.getDevCode() + "]值：" + resultal);


                    } else {
//                TBusiDevMonitorInfoEntity tBusiDevMonitorInfoEntity = new TBusiDevMonitorInfoEntity();
//                tBusiDevMonitorInfoEntity.setLastOpr((long)0);
//                tBusiDevMonitorInfoEntity.setLastTime(new Date());
//                tBusiDevMonitorInfoEntity.setDevCode(devId);
                        tBusiDevMonitorInfoEntity.setVariableKind("00");
                        tBusiDevMonitorInfoEntity.setVariableDesc("暂态地电压");
                        tBusiDevMonitorInfoEntity.setVariableStatus("0");
//                serverHandler.tBusiDevMonitorInfoService.updateMonitorByCodeKindDesc(tBusiDevMonitorInfoEntity);
                    }

                    int upsum2 = serverHandler.tBusiDevMonitorInfoService.updateMonitorByCodeKindDesc(tBusiDevMonitorInfoEntity);
                    if (upsum2 <= 0) {
                        logger.debug("更新暂态地电压状态不存在 updateMonitorByCodeKindDesc-插入");

                        tBusiDevMonitorInfoEntity.setCreateTime(new Date());
                        tBusiDevMonitorInfoEntity.setCreateOpr((long) 0);
                        tBusiDevMonitorInfoEntity.setVariableValue("0");
                        tBusiDevMonitorInfoEntity.setVariableValue2("0");
                        tBusiDevMonitorInfoEntity.setVariableValue3("0");
                        try {
                            String codeStr = getVariableCodeByName(tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableKind(), serverHandler);
                            if (codeStr != null && codeStr != "") {
                                tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                            } else {
                                tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                                logger.debug("code值未配置：name:" + tBusiDevMonitorInfoEntity.getVariableDesc() + " kind:" + tBusiDevMonitorInfoEntity.getVariableKind());
                            }

                            serverHandler.tBusiDevMonitorInfoService.save(tBusiDevMonitorInfoEntity);
                        } catch (Exception e) {
                            logger.debug("monitor 添加失败:暂态地电压");
                        }
                    }

                    tSampBasiDataInfoEntity.setDevSrc(devSrc);
                    tSampBasiDataInfoEntity.setDevId(devId);
                    tSampBasiDataInfoEntity.setModuleName(module);
                    tSampBasiDataInfoEntity.setSampTime(time);
                    tSampBasiDataInfoEntity.setSampState(state);
                    tSampBasiDataInfoEntity.setCreateTime(new Date());
                    tSampBasiDataInfoEntity.setLastTime(new Date());

                    boolean saveflag;
                    logger.debug("保存数据库------");
                    int updsum = serverHandler.tSampBasiDataInfoService.updateSampValueByDevData(tSampBasiDataInfoEntity);
                    if(updsum <= 0) {
                        logger.debug("插入新数据 uploadSampleDataTevRsp tSampBasiDataInfoEntity");
                        saveflag = serverHandler.tSampBasiDataInfoService.save(tSampBasiDataInfoEntity);
                        if (!saveflag) {
                            logger.error("保存数据库失败 uploadSampleDataTevRsp tSampBasiDataInfoEntity");
                            SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataTevRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                            return;
                        }
                    }

                    String ampValue = TevSampleDataobj.getString("ampValue");
                    String ampUnit = TevSampleDataobj.getString("fileSound");
                    String maxAmpValue = TevSampleDataobj.getString("maxAmpValue");
                    String pulseCnt = TevSampleDataobj.getString("pulseCnt");
                    String pdl = TevSampleDataobj.getString("pdl");
                    String filePrpdBg = TevSampleDataobj.getString("filePrpdBg");
                    String fileAllInOneDat = TevSampleDataobj.getString("fileAllInOneDat");
                    //入库或更新操作
                    TSampTevDataInfoEntity tSampTevDataInfoEntity = new TSampTevDataInfoEntity();
                    tSampTevDataInfoEntity.setDevId(devId);
//                    tSampTevDataInfoEntity.setDevIp(devIp);
                    tSampTevDataInfoEntity.setAmpValue(ampValue);
                    tSampTevDataInfoEntity.setAmpUnit(ampUnit);
                    tSampTevDataInfoEntity.setMaxAmpValue(maxAmpValue);
                    tSampTevDataInfoEntity.setPulseCnt(pulseCnt);
                    tSampTevDataInfoEntity.setPdl(pdl);
                    tSampTevDataInfoEntity.setFilePrpd(filePrpdBg);
                    tSampTevDataInfoEntity.setFilePrpdDat(fileAllInOneDat);
                    tSampTevDataInfoEntity.setFilePrpdBg(filePrpdBg);
                    tSampTevDataInfoEntity.setFileAllInOneDat(fileAllInOneDat);
                    tSampTevDataInfoEntity.setCreateTime(new Date());
                    tSampTevDataInfoEntity.setLastTime(new Date());
                    upsum2 = serverHandler.tSampTevDataInfoService.updateByDevId(tSampTevDataInfoEntity);
                    if (upsum2 <= 0) {
                        logger.debug("无更新数据-插入新数据 tSampTevDataInfoService");
                        serverHandler.tSampTevDataInfoService.save(tSampTevDataInfoEntity);
                    }
                    logger.debug("入历史数据 tSampTevDataInfoHisService");
                    TSampTevDataInfoHisEntity tSampTevDataInfoHisEntity = new TSampTevDataInfoHisEntity();
                    BeanUtils.copyProperties(tSampTevDataInfoEntity, tSampTevDataInfoHisEntity);
                    serverHandler.tSampTevDataInfoHisService.save(tSampTevDataInfoHisEntity);
                } else {
                    logger.error("TevSampleData 解析为空");
                }
            } else {
                logger.error("contentobj 解析为空");
            }

            SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataTevRsp", Constant.CMD_OK, null, q_obj, null, null, ctx);

        } catch (Exception ex) {
            logger.error("uploadSampleDataTev error： " + ex);
        }
//        {
//            "action": "uploadSampleDataTev",
//                "msgId": "",
//                "content": {
//            "TevSampleData": {
//                "SampleDataBase": {
//                    "devSrc": "ied",
//                            "devId": "ST10AX123450007",
//                            "module": "TEV",
//                            "time": "2019-08-22 08:17:58",
//                            "state": "normal",
//                            "ExceptionInfoList": [
//                    {
//                        "type": "1",
//                            "confidence": "80",
//                            "msg": ""
//                    }
//]
//                },
//                "noiseBase": [
//                {
//                    "name": "amplitude",
//                        "nb": "30",
//                        "unit": "dBmV"
//                },
//                {
//                    "name": "pulse",
//                        "nb": "500",
//                        "unit": "次"
//                }
//],
//                "ampValue":"356",
//                        "ampUnit":"dBmV",
//                        "maxAmpValue":"",
//                        "pulseCnt":"876",
//                        "pdl":"1275.6",
//                        "filePrpdBg": "MnaieSH10_1_20200419015110.dat",
//                        "fileAllInOneDat": "MnaieST10_20200419015110.dat"
//            }
//        }
//        }
    }

    //终端上传超声采样数据
    public static void uploadSampleDataAe(ServerHandler serverHandler,JSONObject q_obj,JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("uploadSampleDataAe");
        try {
//            String msgId = obj.getString("msgId");

            TBusiDevStatusInfoEntity tBusiDevStatusInfoEntity = new TBusiDevStatusInfoEntity();
            TSampBasiDataInfoEntity tSampBasiDataInfoEntity = new TSampBasiDataInfoEntity();

            JSONObject contentobj = obj.getJSONObject("content");
            if(contentobj!=null) {
                JSONObject AeSampleDataobj = contentobj.getJSONObject("AeSampleData");
                if(AeSampleDataobj != null) {
                    JSONObject SampleDataBaseobj = AeSampleDataobj.getJSONObject("SampleDataBase");
                    String devSrc = SampleDataBaseobj.getString("devSrc");
                    String devId = SampleDataBaseobj.getString("devId");
                    String module = SampleDataBaseobj.getString("module");
                    String time = SampleDataBaseobj.getString("time");
                    String state = SampleDataBaseobj.getString("state");
                    JSONObject ExceptionInfoobj = SampleDataBaseobj.getJSONObject("ExceptionInfo");
                    if (ExceptionInfoobj != null) {
                        String type = ExceptionInfoobj.getString("type");
                        String msg = ExceptionInfoobj.getString("msg");
                        tSampBasiDataInfoEntity.setSampExceptionType(type);
                        tSampBasiDataInfoEntity.setSampExceptionMsg(msg);
                    }

                    JSONArray noiseBasearray = AeSampleDataobj.getJSONArray("noiseBase");
                    if (noiseBasearray != null) {
                        for (int i = 0; i < noiseBasearray.size(); i++) {
                            JSONObject noiseBaseobj = noiseBasearray.getJSONObject(i);
                            String noiseBaseName = noiseBaseobj.getString("name");
                            String noiseBaseNB = noiseBaseobj.getString("nb");
                            String noiseBaseUnit = noiseBaseobj.getString("unit");
                            String measureType = noiseBaseobj.getString("measureType");
//                            String module = noiseBaseobj.getString("module");
//                            String measureType = noiseBaseobj.getString("measureType");
//                            String measureType = noiseBaseobj.getString("measureType");

                            TSampNoiseBaseInfoEntity tSampNoiseBaseInfoEntity = new TSampNoiseBaseInfoEntity();
                            tSampNoiseBaseInfoEntity.setDevSrc(devSrc);
                            tSampNoiseBaseInfoEntity.setDevId(devId);
                            tSampNoiseBaseInfoEntity.setModule(module);
                            tSampNoiseBaseInfoEntity.setMeasureType(measureType);
                            tSampNoiseBaseInfoEntity.setName(noiseBaseName);
                            tSampNoiseBaseInfoEntity.setNb(noiseBaseNB);
                            tSampNoiseBaseInfoEntity.setUnit(noiseBaseUnit);
                            tSampNoiseBaseInfoEntity.setCreateTime(new Date());
                            tSampNoiseBaseInfoEntity.setLastTime(new Date());

                            int upsum = serverHandler.tSampNoiseBaseInfoService.updateNoiseValueByDevData(tSampNoiseBaseInfoEntity);
                            if (upsum <= 0) {
                                logger.debug("无更新数据-插入新数据 uploadSampleDataAe - tSampNoiseBaseInfoService");
                                serverHandler.tSampNoiseBaseInfoService.save(tSampNoiseBaseInfoEntity);
                            }
                            logger.debug("入历史数据 uploadSampleDataAe - tSampNoiseBaseInfoHisService");
                            TSampNoiseBaseInfoHisEntity tSampNoiseBaseInfoHisEntity = new TSampNoiseBaseInfoHisEntity();
                            BeanUtils.copyProperties(tSampNoiseBaseInfoEntity, tSampNoiseBaseInfoHisEntity);
                            serverHandler.tSampNoiseBaseInfoHisService.save(tSampNoiseBaseInfoHisEntity);
                        }
                    }

                    time = dateTimeToString(time);

                    TBusiDevMonitorInfoEntity tBusiDevMonitorInfoEntity = new TBusiDevMonitorInfoEntity();
                    tBusiDevMonitorInfoEntity.setLastOpr((long) 0);
                    tBusiDevMonitorInfoEntity.setLastTime(new Date());
                    tBusiDevMonitorInfoEntity.setDevCode(devId);
                    tBusiDevMonitorInfoEntity.setMonitorTime(time);
                    if (state.equals("warning")) {
                        tBusiDevStatusInfoEntity.setDevCode(devId);
                        tBusiDevStatusInfoEntity.setIsAlarm("1");
                        tBusiDevStatusInfoEntity.setLastOpr((long) 0);
                        tBusiDevStatusInfoEntity.setLastTime(new Date());

                        int upsum = serverHandler.tBusiDevStatusInfoService.updateDevStatusInfoByCode(tBusiDevStatusInfoEntity);
                        if (upsum <= 0) {
                            logger.debug("插入新数据 uploadSampleDataSound tBusiDevStatusInfoEntity");
                            tBusiDevStatusInfoEntity.setCreateTime(new Date());
                            tBusiDevStatusInfoEntity.setCreateOpr((long) 0);
                            tBusiDevStatusInfoEntity.setDevStatus("1");
                            tBusiDevStatusInfoEntity.setIsVaild("1");
//                    serverHandler.tBusiDevStatusInfoService.save(tBusiDevStatusInfoEntity);
                        }

                        tBusiDevMonitorInfoEntity.setVariableKind("00");
                        tBusiDevMonitorInfoEntity.setVariableDesc("超声");
                        tBusiDevMonitorInfoEntity.setVariableStatus("1");

                        Date t = new Date();
                        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                        int resultal = serverHandler.tBusiSysAlarmInfoService.insertAlarmInfoBySystem(df.format(t), tBusiDevMonitorInfoEntity.getDevCode(), "00" + tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableDesc() + "告警");
                        logger.debug("超声插入告警：编号[" + tBusiDevMonitorInfoEntity.getDevCode() + "]值：" + resultal);


                    } else {
                        tBusiDevMonitorInfoEntity.setVariableKind("00");
                        tBusiDevMonitorInfoEntity.setVariableDesc("超声");
                        tBusiDevMonitorInfoEntity.setVariableStatus("0");
                    }

                    int upsum2 = serverHandler.tBusiDevMonitorInfoService.updateMonitorByCodeKindDesc(tBusiDevMonitorInfoEntity);
                    if (upsum2 <= 0) {
                        logger.debug("更新超声状态不存在 updateMonitorByCodeKindDesc-插入");

                        tBusiDevMonitorInfoEntity.setCreateTime(new Date());
                        tBusiDevMonitorInfoEntity.setCreateOpr((long) 0);
                        tBusiDevMonitorInfoEntity.setVariableValue("0");
                        tBusiDevMonitorInfoEntity.setVariableValue2("0");
                        tBusiDevMonitorInfoEntity.setVariableValue3("0");
                        try {
                            String codeStr = getVariableCodeByName(tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableKind(), serverHandler);
                            if (codeStr != null && codeStr != "") {
                                tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                            } else {
                                tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                                logger.debug("code值未配置：name:" + tBusiDevMonitorInfoEntity.getVariableDesc() + " kind:" + tBusiDevMonitorInfoEntity.getVariableKind());
                            }

                            serverHandler.tBusiDevMonitorInfoService.save(tBusiDevMonitorInfoEntity);
                        } catch (Exception e) {
                            logger.debug("monitor 添加失败:超声");
                        }
                    }

                    tSampBasiDataInfoEntity.setDevSrc(devSrc);
                    tSampBasiDataInfoEntity.setDevId(devId);
                    tSampBasiDataInfoEntity.setModuleName(module);
                    tSampBasiDataInfoEntity.setSampTime(time);
                    tSampBasiDataInfoEntity.setSampState(state);
                    tSampBasiDataInfoEntity.setCreateTime(new Date());
                    tSampBasiDataInfoEntity.setLastTime(new Date());

                    boolean saveflag;
                    logger.debug("保存数据库------");
                    int updsum = serverHandler.tSampBasiDataInfoService.updateSampValueByDevData(tSampBasiDataInfoEntity);
                    if(updsum <= 0) {
                        logger.debug("插入新数据 uploadSampleDataAeRsp tSampBasiDataInfoEntity");
                        saveflag = serverHandler.tSampBasiDataInfoService.save(tSampBasiDataInfoEntity);
                        if (!saveflag) {
                            logger.error("保存数据库失败 uploadSampleDataAeRsp tSampBasiDataInfoEntity");
                            SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataAeRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                            return;
                        }
                    }

                    String ampFactor = AeSampleDataobj.getString("ampFactor");
                    String peakValue = AeSampleDataobj.getString("peakValue");
                    String rmsValue = AeSampleDataobj.getString("rmsValue");
                    String ampUnit = AeSampleDataobj.getString("ampUnit");
                    String freq1Content = AeSampleDataobj.getString("freq1Content");
                    String freq2Content = AeSampleDataobj.getString("freq2Content");
                    String filterType = AeSampleDataobj.getString("filterType");
                    String lowerFreq = AeSampleDataobj.getString("lowerFreq");
                    String upperFreq = AeSampleDataobj.getString("upperFreq");
                    String pulseInterval = AeSampleDataobj.getString("pulseInterval");
                    String fileChric = AeSampleDataobj.getString("fileChric");
                    String fileChricDat = AeSampleDataobj.getString("fileChricDat");
                    String fileChricBg = AeSampleDataobj.getString("fileChricBg");
                    String filePrpd = AeSampleDataobj.getString("filePrpd");
                    String filePrpdDat = AeSampleDataobj.getString("filePrpdDat");
                    String filePrpdBg = AeSampleDataobj.getString("filePrpdBg");
                    String fileFlight = AeSampleDataobj.getString("fileFlight");
                    String fileFlightDat = AeSampleDataobj.getString("fileFlightDat");
                    String fileFlightBg = AeSampleDataobj.getString("fileFlightBg");
                    String fileAllInOneDat = AeSampleDataobj.getString("fileAllInOneDat");
                    //入库或更新操作
                    TSampAeDataInfoEntity tSampAeDataInfoEntity = new TSampAeDataInfoEntity();
                    tSampAeDataInfoEntity.setDevId(devId);
//                    tSampAeDataInfoEntity.setDevIp();
                    tSampAeDataInfoEntity.setAmpFactor(ampFactor);
                    tSampAeDataInfoEntity.setPeakValue(peakValue);
                    tSampAeDataInfoEntity.setRmsValue(rmsValue);
//                    tSampAeDataInfoEntity.setAmpUnit(ampUnit);
                    tSampAeDataInfoEntity.setFreq1Content(freq1Content);
                    tSampAeDataInfoEntity.setFreq2Content(freq2Content);
                    tSampAeDataInfoEntity.setFilterType(filterType);
                    tSampAeDataInfoEntity.setLowerFreq(lowerFreq);
                    tSampAeDataInfoEntity.setUpperFreq(upperFreq);
                    tSampAeDataInfoEntity.setPulseInterval(pulseInterval);
                    tSampAeDataInfoEntity.setFileChric(fileChric);
                    tSampAeDataInfoEntity.setFileChricDat(fileChricDat);
                    tSampAeDataInfoEntity.setFileChricBg(fileChricBg);
                    tSampAeDataInfoEntity.setFilePrpd(filePrpd);
                    tSampAeDataInfoEntity.setFilePrpdDat(filePrpdDat);
                    tSampAeDataInfoEntity.setFilePrpdBg(filePrpdBg);
                    tSampAeDataInfoEntity.setFileFlight(fileFlight);
                    tSampAeDataInfoEntity.setFileFlightDat(fileFlightDat);
                    tSampAeDataInfoEntity.setFileFlightBg(fileFlightBg);
                    tSampAeDataInfoEntity.setFileAllInOneDat(fileAllInOneDat);
                    tSampAeDataInfoEntity.setCreateTime(new Date());
                    tSampAeDataInfoEntity.setLastTime(new Date());
                    upsum2 = serverHandler.tSampAeDataInfoService.updateByDevId(tSampAeDataInfoEntity);
                    if (upsum2 <= 0) {
                        logger.debug("无更新数据-插入新数据 tSampAeDataInfoService");
                        serverHandler.tSampAeDataInfoService.save(tSampAeDataInfoEntity);
                    }
                    logger.debug("入历史数据 tSampAeDataInfoHisService");
                    TSampAeDataInfoHisEntity tSampAeDataInfoHisEntity = new TSampAeDataInfoHisEntity();
                    BeanUtils.copyProperties(tSampAeDataInfoEntity, tSampAeDataInfoHisEntity);
                    serverHandler.tSampAeDataInfoHisService.save(tSampAeDataInfoHisEntity);

                } else {
                    logger.error("AeSampleDataobj 解析为空");
                }
            } else {
                logger.error("contentobj 解析为空");
            }


            SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataAeRsp", Constant.CMD_OK, null, q_obj, null, null, ctx);

        } catch (Exception ex) {
            logger.error("uploadSampleDataAe error： " + ex);
        }
//        "action": "uploadSampleDataAe",
//                "msgId": "",
//                "content": {
//            "AeSampleData": {
//                "SampleDataBase": {
//                    "devSrc": "ied",
//                            "devId": "ST10AX123450007",
//                            "module": "AE",
//                            "time": "2019-08-22 08:17:58",
//                            "state": "normal",
//                            "ExceptionInfoList": [
//                    {
//                        "type": "1",
//                            "confidence": "80",
//                            "msg": ""
//                    }
//]
//                },
//                "noiseBase": [
//                {
//                    "name": "amplitude",
//                        "nb": "120",
//                        "unit": "dBuV"
//                }
//],
//                "ampFactor": "60",
//                        "peakValue": "12.3",
//                        "rmsValue": "7.9",
//                        "ampUnit": "dBuV",
//                        "freq1Content": "9.3",
//                        "freq2Content": "6.4",
//                        "filterType": "1",
//                        "lowerFreq": "",
//                        "upperFreq": "",
//                        "pulseInterval": "1",
//                        "fileChric": "20190629_100013_511_chric.png",
//                        "fileChricDat": "MnaieSH10_0_20200419015110.dat",
//                        "fileChricBg": "MnaieSH10_0_20200419015110.dat",
//                        "filePrpd": "20190629_100013_511_prpd.png",
//                        "filePrpdDat": "MnaieT2000_1_20200419015110.dat",
//                        "filePrpdBg": "MnaieT2000_1_20200419015110.dat",
//                        "fileFlight": "20190629_100013_511_flight.png",
//                        "fileFlightDat": "MnaieT2000_2_20200419015110.dat",
//                        "fileFlightBg": "MnaieT2000_2_20200419015110.dat",
//                "fileAllInOneDat": "MnaieST10_20200419015110.dat"
//            }
//        }
    }

    //终端上传高频电流传感器采样数据
    public static void uploadSampleDataHfct(ServerHandler serverHandler,JSONObject q_obj,JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("uploadSampleDataHfct");
        try {
//            String msgId = obj.getString("msgId");
            TSampJfDataInfoEntity tSampJfDataInfoEntity = new TSampJfDataInfoEntity();
            TSampBasiDataInfoEntity tSampBasiDataInfoEntity = new TSampBasiDataInfoEntity();

            JSONObject contentobj = obj.getJSONObject("content");
            if (contentobj != null) {
                JSONObject JfSampleDataobj = contentobj.getJSONObject("JfSampleData");
                if (JfSampleDataobj != null) {
                    JSONObject SampleDataBaseobj = JfSampleDataobj.getJSONObject("SampleDataBase");
                    if (SampleDataBaseobj != null) {
                        String devSrc = SampleDataBaseobj.getString("devSrc");
                        String devId = SampleDataBaseobj.getString("devId");
                        String module = SampleDataBaseobj.getString("module");
                        String time = SampleDataBaseobj.getString("time");
                        String state = SampleDataBaseobj.getString("state");
                        JSONObject ExceptionInfoobj = SampleDataBaseobj.getJSONObject("ExceptionInfo");
                        if (ExceptionInfoobj != null) {
                            String type = ExceptionInfoobj.getString("type");
                            String msg = ExceptionInfoobj.getString("msg");
                            tSampBasiDataInfoEntity.setSampExceptionType(type);
                            tSampBasiDataInfoEntity.setSampExceptionMsg(msg);
                        }

                        time = dateTimeToString(time);

                        TBusiDevMonitorInfoEntity tBusiDevMonitorInfoEntity = new TBusiDevMonitorInfoEntity();
                        tBusiDevMonitorInfoEntity.setLastOpr((long)0);
                        tBusiDevMonitorInfoEntity.setLastTime(new Date());
                        tBusiDevMonitorInfoEntity.setDevCode(devId);
                        tBusiDevMonitorInfoEntity.setMonitorTime(time);

                        TBusiDevStatusInfoEntity tBusiDevStatusInfoEntity = new TBusiDevStatusInfoEntity();
                        if(state.equals("warning")){
                            tBusiDevStatusInfoEntity.setDevCode(devId);
                            tBusiDevStatusInfoEntity.setIsAlarm("1");
                            tBusiDevStatusInfoEntity.setLastOpr((long)0);
                            tBusiDevStatusInfoEntity.setLastTime(new Date());

                            int upsum = serverHandler.tBusiDevStatusInfoService.updateDevStatusInfoByCode(tBusiDevStatusInfoEntity);
                            if(upsum <= 0) {
                                logger.debug("插入新数据 uploadSampleDataHfct tBusiDevStatusInfoEntity");
                                tBusiDevStatusInfoEntity.setCreateTime(new Date());
                                tBusiDevStatusInfoEntity.setCreateOpr((long)0);
                                tBusiDevStatusInfoEntity.setDevStatus("1");
                                tBusiDevStatusInfoEntity.setIsVaild("1");
//                                serverHandler.tBusiDevStatusInfoService.save(tBusiDevStatusInfoEntity);
                            }

//                            TBusiDevMonitorInfoEntity tBusiDevMonitorInfoEntity = new TBusiDevMonitorInfoEntity();
//                            tBusiDevMonitorInfoEntity.setLastOpr((long)0);
//                            tBusiDevMonitorInfoEntity.setLastTime(new Date());
//                            tBusiDevMonitorInfoEntity.setDevCode(devId);
                            tBusiDevMonitorInfoEntity.setVariableKind("00");
                            tBusiDevMonitorInfoEntity.setVariableDesc("局放");
                            tBusiDevMonitorInfoEntity.setVariableStatus("1");
                            Date t = new Date();
                            SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                            int resultal = serverHandler.tBusiSysAlarmInfoService.insertAlarmInfoBySystem(df.format(t), tBusiDevMonitorInfoEntity.getDevCode(), "00" + tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableDesc() + "告警");
                            logger.debug("高频局放插入告警：编号[" + tBusiDevMonitorInfoEntity.getDevCode() + "]值：" + resultal);

//                            upsum = serverHandler.tBusiDevMonitorInfoService.updateMonitorByCodeKindDesc(tBusiDevMonitorInfoEntity);
//                            if(upsum <= 0) {
//                                logger.debug("更新局放高频状态不存在 updateMonitorByCodeKindDesc");
//                            }
                            String alarmType = "11";
                            AlarmSendingOutInfo alarmOutInfo = new AlarmSendingOutInfo();
                            alarmOutInfo.setDevCode(tBusiDevMonitorInfoEntity.getDevCode());
                            alarmOutInfo.setAlarmType(alarmType);
                            alarmOutInfo.setAlarmValue("2");
                            InitPointInfoDataConfService.cache2.put(tBusiDevMonitorInfoEntity.getDevCode() + tBusiDevMonitorInfoEntity.getVariableDesc(),alarmOutInfo);
                            logger.debug("外送高频局放红外热像告警:设备编号["+tBusiDevMonitorInfoEntity.getDevCode()+"]"+tBusiDevMonitorInfoEntity.getVariableDesc()+"["+alarmType+"]登记告警2");
                            runClientSendData.runNettyClient(alarmType,"2",tBusiDevMonitorInfoEntity.getDevCode());
                        }else{
                            tBusiDevMonitorInfoEntity.setVariableKind("00");
                            tBusiDevMonitorInfoEntity.setVariableDesc("局放");
                            tBusiDevMonitorInfoEntity.setVariableStatus("0");
//                            int upsum = serverHandler.tBusiDevMonitorInfoService.updateMonitorByCodeKindDesc(tBusiDevMonitorInfoEntity);
//                            if(upsum <= 0) {
//                                logger.debug("更新局放高频状态不存在 updateMonitorByCodeKindDesc");
//                            }

                            AlarmSendingOutInfo alarmOutInfo = InitPointInfoDataConfService.cache2.get(tBusiDevMonitorInfoEntity.getDevCode() + tBusiDevMonitorInfoEntity.getVariableDesc());
                            if(alarmOutInfo != null){
                                if(alarmOutInfo.getAlarmValue().equals("2")){
                                    logger.debug("外送高频局放取消告警:设备编号["+tBusiDevMonitorInfoEntity.getDevCode()+"]"+tBusiDevMonitorInfoEntity.getVariableDesc()+"["+alarmOutInfo.getAlarmType()+"]取消告警1");
                                    runClientSendData.runNettyClient(alarmOutInfo.getAlarmType(),"1",tBusiDevMonitorInfoEntity.getDevCode());

                                    alarmOutInfo.setAlarmValue("1");
                                    InitPointInfoDataConfService.cache2.put(tBusiDevMonitorInfoEntity.getDevCode() + tBusiDevMonitorInfoEntity.getVariableDesc(),alarmOutInfo);
                                }
                            }else{
                                logger.debug("高频局放未找到告警记录无需外送告警");
                            }
                        }

                        int upsum2 = serverHandler.tBusiDevMonitorInfoService.updateMonitorByCodeKindDesc(tBusiDevMonitorInfoEntity);
                        if(upsum2 <= 0) {
                            logger.debug("更新局放高频状态不存在 updateMonitorByCodeKindDesc-插入");

                            tBusiDevMonitorInfoEntity.setCreateTime(new Date());
                            tBusiDevMonitorInfoEntity.setCreateOpr((long)0);
                            tBusiDevMonitorInfoEntity.setVariableValue("0");
                            tBusiDevMonitorInfoEntity.setVariableValue2("0");
                            tBusiDevMonitorInfoEntity.setVariableValue3("0");
                            try {
                                String codeStr = getVariableCodeByName(tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableKind(), serverHandler);
                                if (codeStr != null && codeStr != "") {
                                    tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                                } else {
                                    tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                                    logger.debug("code值未配置：name:" + tBusiDevMonitorInfoEntity.getVariableDesc() + " kind:" + tBusiDevMonitorInfoEntity.getVariableKind());
                                }
                                serverHandler.tBusiDevMonitorInfoService.save(tBusiDevMonitorInfoEntity);
                            }catch(Exception e){
                                logger.debug("monitor 添加失败:局放");
                            }
                        }

                        tSampBasiDataInfoEntity.setDevSrc(devSrc);
                        tSampBasiDataInfoEntity.setDevId(devId);
                        tSampBasiDataInfoEntity.setModuleName(module);
                        tSampBasiDataInfoEntity.setSampTime(time);
                        tSampBasiDataInfoEntity.setSampState(state);
                        tSampBasiDataInfoEntity.setCreateTime(new Date());
                        tSampBasiDataInfoEntity.setLastTime(new Date());

                        tSampJfDataInfoEntity.setDevId(devId);
                    }
                }

                String AvDsch = JfSampleDataobj.getString("AvDsch");
                String MaxDsch = JfSampleDataobj.getString("MaxDsch");
                String DschCnt = JfSampleDataobj.getString("DschCnt");
                String DschPhase = JfSampleDataobj.getString("DschPhase");
                String filePrpd = JfSampleDataobj.getString("filePrpd");
                String filePrps = JfSampleDataobj.getString("filePrps");
                tSampJfDataInfoEntity.setAvDsch(AvDsch);
                tSampJfDataInfoEntity.setMaxDsch(MaxDsch);
                tSampJfDataInfoEntity.setDschCnt(DschCnt);
                tSampJfDataInfoEntity.setDschPhase(DschPhase);
                tSampJfDataInfoEntity.setFilePrpd(filePrpd);
                tSampJfDataInfoEntity.setFilePrps(filePrps);
                //入库或更新操作

                boolean saveflag;
                logger.debug("保存数据库------");
                int updsum = serverHandler.tSampBasiDataInfoService.updateSampValueByDevData(tSampBasiDataInfoEntity);
                if(updsum <= 0) {
                    logger.debug("插入新数据 uploadSampleDataHfctRsp tSampBasiDataInfoEntity");
                    saveflag = serverHandler.tSampBasiDataInfoService.save(tSampBasiDataInfoEntity);
                    if (!saveflag) {
                        logger.error("保存数据库失败 uploadSampleDataHfctRsp tSampBasiDataInfoEntity");
                        SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataHfctRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                        return;
                    }
                }
                updsum = serverHandler.tSampJfDataInfoService.updateByDevId(tSampJfDataInfoEntity);
                tSampJfDataInfoEntity.setCreateTime(new Date());
                tSampJfDataInfoEntity.setLastTime(new Date());
                if(updsum <= 0) {
                    logger.debug("插入新数据 uploadSampleDataHfctRsp tSampJfDataInfoEntity");
                    saveflag = serverHandler.tSampJfDataInfoService.save(tSampJfDataInfoEntity);
                    if (!saveflag) {
                        logger.error("保存数据库失败 uploadSampleDataHfctRsp tSampJfDataInfoEntity");
                        SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataHfctRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                        return;
                    }
                    logger.debug("保存基础数据库完成");
                }

                TSampJfDataInfoHisEntity tSampJfDataInfoHisEntity = new TSampJfDataInfoHisEntity();
                BeanUtils.copyProperties(tSampJfDataInfoEntity, tSampJfDataInfoHisEntity);
                saveflag = serverHandler.tSampJfDataInfoHisService.save(tSampJfDataInfoHisEntity);
                if (!saveflag) {
                    logger.error("保存数据库失败 uploadSampleDataHfctRsp tSampJfDataInfoHisEntity");
                    SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataHfctRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                    return;
                }
                logger.debug("保存基础数据库完成");
            }

            SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataHfctRsp", Constant.CMD_OK, null, q_obj, null, null, ctx);

        } catch (Exception ex) {
            logger.error("uploadSampleDataHfctRsp error： " + ex);
        }
//        "action": "uploadSampleDataHfct",
//                "msgId": "",
//                "content": {
//            "JfSampleData": {
//                "SampleDataBase": {
//                    "devSrc": "ied",
//                            "devId": "SU10AX123450007",
//                            "module": "HFCT",
//                            "time": "2019-08-22 08:17:58",
//                            "state": "normal",
//                            "ExceptionInfo": {
//                        "type": "1",
//                                "msg": "88%"
//                    }
//                },
//                "AvDsch": "196",
//                        "MaxDsch": "687",
//                        "DschCnt": "1156",
//                        "DschPhase": "258",
//                        "filePrpd": "20190629_100013_511_prpd.png",
//                        "filePrps": "20190629_160616_088_prps.png"
//            }
//        }
    }

    //终端上传系统信息采样数据
    public static void uploadSampleDataSystem(ServerHandler serverHandler,JSONObject q_obj, JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("uploadSampleDataSystem");
        try {
            String msgId = obj.getString("msgId");

            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject DevSystemDataobj = contentobj.getJSONObject("DevSystemData");
            TSampBasiDataInfoEntity tSampBasiDataInfoEntity = new TSampBasiDataInfoEntity();
            TSampDevDataInfoEntity tSampDevDataInfoEntity = new TSampDevDataInfoEntity();
            if (DevSystemDataobj != null) {
                JSONObject SampleDataBaseobj = DevSystemDataobj.getJSONObject("SampleDataBase");
                if (SampleDataBaseobj != null) {
                    logger.debug("SampleDataBaseobj");
                    String devSrc = SampleDataBaseobj.getString("devSrc");
                    String devId = SampleDataBaseobj.getString("devId");
                    String module = SampleDataBaseobj.getString("module");
                    String time = SampleDataBaseobj.getString("time");
                    String state = SampleDataBaseobj.getString("state");
                    JSONObject ExceptionInfoobj = SampleDataBaseobj.getJSONObject("ExceptionInfo");
                    if (ExceptionInfoobj != null) {
                        logger.debug("ExceptionInfoobj");
                        String type = ExceptionInfoobj.getString("type");
                        String msg = ExceptionInfoobj.getString("msg");
                        tSampBasiDataInfoEntity.setSampExceptionType(type);
                        tSampBasiDataInfoEntity.setSampExceptionMsg(msg);
                    }

                    time = dateTimeToString(time);

                    TBusiDevMonitorInfoEntity tBusiDevMonitorInfoEntity = new TBusiDevMonitorInfoEntity();
                    tBusiDevMonitorInfoEntity.setLastOpr((long)0);
                    tBusiDevMonitorInfoEntity.setLastTime(new Date());
                    tBusiDevMonitorInfoEntity.setDevCode(devId);
                    tBusiDevMonitorInfoEntity.setMonitorTime(time);

                    TBusiDevStatusInfoEntity tBusiDevStatusInfoEntity = new TBusiDevStatusInfoEntity();
                    if(state.equals("warning")){
                        tBusiDevStatusInfoEntity.setDevCode(devId);
                        tBusiDevStatusInfoEntity.setIsAlarm("1");
                        tBusiDevStatusInfoEntity.setLastOpr((long)0);
                        tBusiDevStatusInfoEntity.setLastTime(new Date());

                        int upsum = serverHandler.tBusiDevStatusInfoService.updateDevStatusInfoByCode(tBusiDevStatusInfoEntity);
                        if(upsum <= 0) {
                            logger.debug("插入新数据 uploadSampleDataSystem tBusiDevStatusInfoEntity");
                            tBusiDevStatusInfoEntity.setCreateTime(new Date());
                            tBusiDevStatusInfoEntity.setCreateOpr((long)0);
                            tBusiDevStatusInfoEntity.setDevStatus("1");
                            tBusiDevStatusInfoEntity.setIsVaild("1");
//                            serverHandler.tBusiDevStatusInfoService.save(tBusiDevStatusInfoEntity);
                        }


                        tBusiDevMonitorInfoEntity.setVariableKind("00");
                        tBusiDevMonitorInfoEntity.setVariableDesc("系统");
                        tBusiDevMonitorInfoEntity.setVariableStatus("1");
                        Date t = new Date();
                        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                        int resultal = serverHandler.tBusiSysAlarmInfoService.insertAlarmInfoBySystem(df.format(t), tBusiDevMonitorInfoEntity.getDevCode(), "00" + tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableDesc() + "告警");
                        logger.debug("系统插入告警：编号[" + tBusiDevMonitorInfoEntity.getDevCode() + "]值：" + resultal);

//                        upsum = serverHandler.tBusiDevMonitorInfoService.updateMonitorByCodeKindDesc(tBusiDevMonitorInfoEntity);
//                        if(upsum <= 0) {
//                            logger.debug("更新系统状态不存在 updateMonitorByCodeKindDesc");
//                        }
                    }else{
                        tBusiDevMonitorInfoEntity.setVariableKind("00");
                        tBusiDevMonitorInfoEntity.setVariableDesc("系统");
                        tBusiDevMonitorInfoEntity.setVariableStatus("0");
                    }

                    int upsum2 = serverHandler.tBusiDevMonitorInfoService.updateMonitorByCodeKindDesc(tBusiDevMonitorInfoEntity);
                    if(upsum2 <= 0) {
                        logger.debug("更新系统状态不存在 updateMonitorByCodeKindDesc");
                        tBusiDevMonitorInfoEntity.setCreateTime(new Date());
                        tBusiDevMonitorInfoEntity.setCreateOpr((long)0);
                        tBusiDevMonitorInfoEntity.setVariableValue("0");
                        tBusiDevMonitorInfoEntity.setVariableValue2("0");
                        tBusiDevMonitorInfoEntity.setVariableValue3("0");
                        try {
                            String codeStr = getVariableCodeByName(tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableKind(), serverHandler);
                            if (codeStr != null && codeStr != "") {
                                tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                            } else {
                                tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                                logger.debug("code值未配置：name:" + tBusiDevMonitorInfoEntity.getVariableDesc() + " kind:" + tBusiDevMonitorInfoEntity.getVariableKind());
                            }
                            serverHandler.tBusiDevMonitorInfoService.save(tBusiDevMonitorInfoEntity);
                        }catch(Exception e){
                            logger.debug("monitor 添加失败:系统");
                        }
                    }


                    tSampBasiDataInfoEntity.setDevSrc(devSrc);
                    tSampBasiDataInfoEntity.setDevId(devId);
                    tSampBasiDataInfoEntity.setModuleName(module);
                    tSampBasiDataInfoEntity.setSampTime(time);
                    tSampBasiDataInfoEntity.setSampState(state);
                    tSampBasiDataInfoEntity.setCreateTime(new Date());
                    tSampBasiDataInfoEntity.setLastTime(new Date());

                    tSampDevDataInfoEntity.setDevId(devId);
                }
                JSONObject IPInfoobj = DevSystemDataobj.getJSONObject("IPInfo");
                if (IPInfoobj != null) {
                    logger.debug("IPInfoobj");
                    String ipVersion = IPInfoobj.getString("ipVersion");
                    String ipType = IPInfoobj.getString("ipType");
                    String ipAddress = IPInfoobj.getString("ipAddress");
                    String mask = IPInfoobj.getString("mask");
                    String gateway = IPInfoobj.getString("gateway");
                    String dns = IPInfoobj.getString("dns");

                    tSampDevDataInfoEntity.setIpVersion(ipVersion);
                    tSampDevDataInfoEntity.setIpType(ipType);
                    tSampDevDataInfoEntity.setIpAddress(ipAddress);
                    tSampDevDataInfoEntity.setIpMask(mask);
                    tSampDevDataInfoEntity.setIpGateway(gateway);
                    tSampDevDataInfoEntity.setIpDns(dns);
                }
                JSONObject WiFiInfoobj = DevSystemDataobj.getJSONObject("WiFiInfo");
                if (WiFiInfoobj != null) {
                    logger.debug("WiFiInfoobj");
                    String ssid = WiFiInfoobj.getString("ssid");
                    String wifiEnable = WiFiInfoobj.getString("wifiEnable");

                    tSampDevDataInfoEntity.setWifiSsid(ssid);
                    tSampDevDataInfoEntity.setWifiStatus(wifiEnable);
                }
                JSONObject SimInfoobj = DevSystemDataobj.getJSONObject("SimInfo");
                if (SimInfoobj != null) {
                    logger.debug("SimInfoobj");
                    String signalLevel = SimInfoobj.getString("signalLevel");
                    String phoneNumber = SimInfoobj.getString("phoneNumber");

                    tSampDevDataInfoEntity.setSimSignalLevel(signalLevel);
                    tSampDevDataInfoEntity.setSimPhoneNumber(phoneNumber);
                }

                String deviceName = DevSystemDataobj.getString("deviceName");
                String serial = DevSystemDataobj.getString("serial");
                String version = DevSystemDataobj.getString("version");
                String gps = DevSystemDataobj.getString("gps");
                String cpu = DevSystemDataobj.getString("cpu");
                String rom = DevSystemDataobj.getString("rom");
                String ram = DevSystemDataobj.getString("ram");
                String cpuTemp = DevSystemDataobj.getString("cpuTemp");
                String boardTemp = DevSystemDataobj.getString("boardTemp");
                String batteryLevel = DevSystemDataobj.getString("batteryLevel");
                String batteryTemp = DevSystemDataobj.getString("batteryTemp");
                String hwVersion = DevSystemDataobj.getString("hwVersion");
                String loraVersion = DevSystemDataobj.getString("loraVersion");
                String chargerState = DevSystemDataobj.getString("chargerState");
                String snr = DevSystemDataobj.getString("snr");
                String rssi = DevSystemDataobj.getString("rssi");

                tSampDevDataInfoEntity.setDeviceName(deviceName);
                tSampDevDataInfoEntity.setSerial(serial);
                tSampDevDataInfoEntity.setVersion(version);
                tSampDevDataInfoEntity.setGps(gps);
                tSampDevDataInfoEntity.setCpu(cpu);
                tSampDevDataInfoEntity.setRom(rom);
                tSampDevDataInfoEntity.setRam(ram);
                tSampDevDataInfoEntity.setCpuTemp(cpuTemp);
                tSampDevDataInfoEntity.setBoardTemp(boardTemp);
                tSampDevDataInfoEntity.setBatteryLevel(batteryLevel);
                tSampDevDataInfoEntity.setBatteryTemp(batteryTemp);
                tSampDevDataInfoEntity.setHwVersion(hwVersion);
                tSampDevDataInfoEntity.setLoraVersion(loraVersion);
                tSampDevDataInfoEntity.setChargerState(chargerState);
                tSampDevDataInfoEntity.setSnr(snr);
                tSampDevDataInfoEntity.setRssi(rssi);

                tSampDevDataInfoEntity.setCreateTime(new Date());
                tSampDevDataInfoEntity.setLastTime(new Date());
            }
            //入库或更新操作
            boolean saveflag;
            logger.debug("保存数据库操作------");

            int updsum = serverHandler.tSampBasiDataInfoService.updateSampValueByDevData(tSampBasiDataInfoEntity);
            if(updsum <= 0) {
                logger.debug("插入新数据 uploadSampleDataSystemRsp tSampBasiDataInfoEntity");
                saveflag = serverHandler.tSampBasiDataInfoService.save(tSampBasiDataInfoEntity);
                if (!saveflag) {
                    logger.error("保存数据库操作失败 uploadSampleDataSystemRsp tSampBasiDataInfoEntity");
                    SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataSystemRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                    return;
                }
            }
            updsum = serverHandler.tSampDevDataInfoService.updateByDevId(tSampDevDataInfoEntity);
            if(updsum <= 0) {
                logger.debug("插入新数据 uploadSampleDataSystemRsp tSampDevDataInfoEntity");
                saveflag = serverHandler.tSampDevDataInfoService.save(tSampDevDataInfoEntity);
                if (!saveflag) {
                    logger.error("保存数据库操作失败 uploadSampleDataSystemRsp tSampDevDataInfoEntity");
                    SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataSystemRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                    return;
                }
                logger.debug("保存数据库操作完成");
            }

            TSampDevDataInfoHisEntity tSampDevDataInfoHisEntity = new TSampDevDataInfoHisEntity();
            BeanUtils.copyProperties(tSampDevDataInfoEntity, tSampDevDataInfoHisEntity);
            saveflag = serverHandler.tSampDevDataInfoHisService.save(tSampDevDataInfoHisEntity);
            if (!saveflag) {
                logger.error("保存数据库操作失败 uploadSampleDataSystemRsp tSampDevDataInfoHisEntity");
                SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataSystemRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                return;
            }

            SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataSystemRsp", Constant.CMD_OK, null, q_obj, null, null, ctx);

        } catch (Exception ex) {
            logger.error("uploadSampleDataSystem error： " + ex);
        }
//        "action": "uploadSampleDataSystem",
//                "content": {
//            "DevSystemData": {
//                "SampleDataBase": {
//                    "devSrc": "dev",
//                            "devId": "TP01MN2181221000042",
//                            "module": "system",
//                            "time": "2019-08-22 08:17:58",
//                            "state": "normal",
//                            "ExceptionInfo": {
//                        "type": "1",
//                                "msg": "88%"
//                    }
//                },
//                "IPInfo": {
//                    "ipVersion": "IPv4",
//                            "ipType": "dhcp",
//                            "ipAddress": "192.168.0.184",
//                            "mask": "255.255.255.0",
//                            "gateway": "",
//                            "dns": ""
//                },
//                "WiFiInfo": {
//                    "ssid": "MN-MP01MN1190601000232",
//                    "wifiEnable": "关闭"
//                },
//                "SimInfo": {
//                    "signalLevel": "0",
//                            "phoneNumber": ""
//                },
//                "deviceName": "T2000",
//                        "serial": "MP01MN1190601000232",
//                        "version": "T2000__CH_U_V190715BCF2FF21",
//                        "gps": ",",
//                        "cpu": "26.1%",
//                        "rom": "5%",
//                        "ram": "52%",
//                        "cpuTemp": "37",
//                        "boardTemp": "32",
//                        "batteryLevel": "255",
//                        "batteryTemp": "55",
//                        "hwVersion": "V1.0",
//                        "loraVersion": "V1.1",
//                        "chargerState": "0",
//                        "snr": "15",
//                        "rssi": "13"
//            }
//        }
    }

    //终端上传温湿度计采样数据
    public static void uploadSampleDataTH(ServerHandler serverHandler,JSONObject q_obj,JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("uploadSampleDataTH");
        try {
            String msgId = obj.getString("msgId");
            TSampThDataInfoEntity tSampThDataInfoEntity = new TSampThDataInfoEntity();
            TSampBasiDataInfoEntity tSampBasiDataInfoEntity = new TSampBasiDataInfoEntity();
            TBusiDevMonitorInfoEntity tBusiDevMonitorInfoEntity = new TBusiDevMonitorInfoEntity();

            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject THSampleDataobj = contentobj.getJSONObject("THSampleData");
            if (THSampleDataobj != null) {
                JSONObject SampleDataBaseobj = THSampleDataobj.getJSONObject("SampleDataBase");
                if (SampleDataBaseobj != null) {
                    logger.debug("SampleDataBaseobj");
                    String devSrc = SampleDataBaseobj.getString("devSrc");
                    String devId = SampleDataBaseobj.getString("devId");
                    String module = SampleDataBaseobj.getString("module");
                    String time = SampleDataBaseobj.getString("time");
                    String state = SampleDataBaseobj.getString("state");
                    JSONObject ExceptionInfoobj = SampleDataBaseobj.getJSONObject("ExceptionInfo");
                    if (ExceptionInfoobj != null) {
                        logger.debug("ExceptionInfoobj");
                        String type = ExceptionInfoobj.getString("type");
                        String msg = ExceptionInfoobj.getString("msg");
                        tSampBasiDataInfoEntity.setSampExceptionType(type);
                        tSampBasiDataInfoEntity.setSampExceptionMsg(msg);
                    }

                    time = dateTimeToString(time);

                    tBusiDevMonitorInfoEntity.setLastOpr((long)0);
                    tBusiDevMonitorInfoEntity.setLastTime(new Date());
                    tBusiDevMonitorInfoEntity.setDevCode(devId);
                    tBusiDevMonitorInfoEntity.setMonitorTime(time);

                    TBusiDevStatusInfoEntity tBusiDevStatusInfoEntity = new TBusiDevStatusInfoEntity();
                    if(state.equals("warning")){
                        tBusiDevStatusInfoEntity.setDevCode(devId);
                        tBusiDevStatusInfoEntity.setIsAlarm("1");
                        tBusiDevStatusInfoEntity.setLastOpr((long)0);
                        tBusiDevStatusInfoEntity.setLastTime(new Date());

                        int upsum = serverHandler.tBusiDevStatusInfoService.updateDevStatusInfoByCode(tBusiDevStatusInfoEntity);
                        if(upsum <= 0) {
                            logger.debug("插入新数据 uploadSampleDataIr tBusiDevStatusInfoEntity");
                            tBusiDevStatusInfoEntity.setCreateTime(new Date());
                            tBusiDevStatusInfoEntity.setCreateOpr((long)0);
                            tBusiDevStatusInfoEntity.setDevStatus("1");
                            tBusiDevStatusInfoEntity.setIsVaild("1");
//                            serverHandler.tBusiDevStatusInfoService.save(tBusiDevStatusInfoEntity);
                        }


                        tBusiDevMonitorInfoEntity.setVariableKind("00");
                        tBusiDevMonitorInfoEntity.setVariableDesc("温度");
                        tBusiDevMonitorInfoEntity.setVariableStatus("1");

                        Date t = new Date();
                        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                        int resultal = serverHandler.tBusiSysAlarmInfoService.insertAlarmInfoBySystem(df.format(t), tBusiDevMonitorInfoEntity.getDevCode(), "00" + tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableDesc() + "告警");
                        logger.debug("温度插入告警：编号[" + tBusiDevMonitorInfoEntity.getDevCode() + "]值：" + resultal);


                    }else{
                        tBusiDevMonitorInfoEntity.setVariableKind("00");
                        tBusiDevMonitorInfoEntity.setVariableDesc("温度");
                        tBusiDevMonitorInfoEntity.setVariableStatus("0");
                    }

                    tSampBasiDataInfoEntity.setDevSrc(devSrc);
                    tSampBasiDataInfoEntity.setDevId(devId);
                    tSampBasiDataInfoEntity.setModuleName(module);
                    tSampBasiDataInfoEntity.setSampTime(time);
                    tSampBasiDataInfoEntity.setSampState(state);
                    tSampBasiDataInfoEntity.setCreateTime(new Date());
                    tSampBasiDataInfoEntity.setLastTime(new Date());

                    tSampThDataInfoEntity.setDevId(devId);
                }

                String ambientTemp = THSampleDataobj.getString("ambientTemp");
                String relativeHumidity = THSampleDataobj.getString("relativeHumidity");
                String pressure = THSampleDataobj.getString("pressure");

                tSampThDataInfoEntity.setAmbientTemp(ambientTemp);
                tSampThDataInfoEntity.setRelativeHumidity(relativeHumidity);
                tSampThDataInfoEntity.setPressure(pressure);
                tSampThDataInfoEntity.setCreateTime(new Date());
                tSampThDataInfoEntity.setLastTime(new Date());

                tBusiDevMonitorInfoEntity.setVariableDesc("温度");
                tBusiDevMonitorInfoEntity.setVariableValue(ambientTemp);
                int upsum = serverHandler.tBusiDevMonitorInfoService.updateMonitorByCodeKindDesc(tBusiDevMonitorInfoEntity);
                if(upsum <= 0) {
                    logger.debug("更新温度状态不存在 updateMonitorByCodeKindDesc");
                    tBusiDevMonitorInfoEntity.setCreateTime(new Date());
                    tBusiDevMonitorInfoEntity.setCreateOpr((long)0);
//                    tBusiDevMonitorInfoEntity.setVariableValue("0");
                    tBusiDevMonitorInfoEntity.setVariableValue2("0");
                    tBusiDevMonitorInfoEntity.setVariableValue3("0");
                    try {
                        String codeStr = getVariableCodeByName(tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableKind(), serverHandler);
                        if (codeStr != null && codeStr != "") {
                            tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                        } else {
                            tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                            logger.debug("code值未配置：name:" + tBusiDevMonitorInfoEntity.getVariableDesc() + " kind:" + tBusiDevMonitorInfoEntity.getVariableKind());
                        }
                        serverHandler.tBusiDevMonitorInfoService.save(tBusiDevMonitorInfoEntity);
                    }catch(Exception e){
                        logger.debug("monitor 添加失败:温度");
                    }
                }

                tBusiDevMonitorInfoEntity.setVariableDesc("湿度");
                tBusiDevMonitorInfoEntity.setVariableValue(relativeHumidity);
                upsum = serverHandler.tBusiDevMonitorInfoService.updateMonitorByCodeKindDesc(tBusiDevMonitorInfoEntity);
                if(upsum <= 0) {
                    logger.debug("更新温度状态不存在 updateMonitorByCodeKindDesc-插入");
                    tBusiDevMonitorInfoEntity.setCreateTime(new Date());
                    tBusiDevMonitorInfoEntity.setCreateOpr((long)0);
//                    tBusiDevMonitorInfoEntity.setVariableValue("0");
                    tBusiDevMonitorInfoEntity.setVariableValue2("0");
                    tBusiDevMonitorInfoEntity.setVariableValue3("0");
                    try {
                        String codeStr = getVariableCodeByName(tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableKind(), serverHandler);
                        if (codeStr != null && codeStr != "") {
                            tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                        } else {
                            tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                            logger.debug("code值未配置：name:" + tBusiDevMonitorInfoEntity.getVariableDesc() + " kind:" + tBusiDevMonitorInfoEntity.getVariableKind());
                        }
                        serverHandler.tBusiDevMonitorInfoService.save(tBusiDevMonitorInfoEntity);
                    }catch(Exception e){
                        logger.debug("monitor 添加失败:湿度");
                    }
                }

                tBusiDevMonitorInfoEntity.setVariableDesc("气压");
                tBusiDevMonitorInfoEntity.setVariableValue(relativeHumidity);
                upsum = serverHandler.tBusiDevMonitorInfoService.updateMonitorByCodeKindDesc(tBusiDevMonitorInfoEntity);
                if(upsum <= 0) {
                    logger.debug("更新气压状态不存在 updateMonitorByCodeKindDesc");
                    tBusiDevMonitorInfoEntity.setCreateTime(new Date());
                    tBusiDevMonitorInfoEntity.setCreateOpr((long)0);
//                    tBusiDevMonitorInfoEntity.setVariableValue("0");
                    tBusiDevMonitorInfoEntity.setVariableValue2("0");
                    tBusiDevMonitorInfoEntity.setVariableValue3("0");
                    try {
                        String codeStr = getVariableCodeByName(tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableKind(), serverHandler);
                        if (codeStr != null && codeStr != "") {
                            tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                        } else {
                            tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                            logger.debug("code值未配置：name:" + tBusiDevMonitorInfoEntity.getVariableDesc() + " kind:" + tBusiDevMonitorInfoEntity.getVariableKind());
                        }
                        serverHandler.tBusiDevMonitorInfoService.save(tBusiDevMonitorInfoEntity);
                    }catch(Exception e){
                        logger.debug("monitor 添加失败:气压");
                    }
                }

            }



            //入库或更新操作
            logger.debug("保存数据------");
            boolean saveflag;
            int updsum = serverHandler.tSampThDataInfoService.updateByDevId(tSampThDataInfoEntity);
            if(updsum <= 0) {
                logger.debug("插入新数据 uploadSampleDataTHRsp tSampBasiDataInfoEntity");
                saveflag = serverHandler.tSampThDataInfoService.save(tSampThDataInfoEntity);
                if (!saveflag) {
                    logger.error("保存数据库失败 uploadSampleDataTHRsp tSampThDataInfoEntity");
                    SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataTHRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                    return;
                }
            }

            TSampThDataInfoHisEntity tSampThDataInfoHisEntity = new TSampThDataInfoHisEntity();
            BeanUtils.copyProperties(tSampThDataInfoEntity, tSampThDataInfoHisEntity);
            saveflag = serverHandler.tSampThDataInfoHisService.save(tSampThDataInfoHisEntity);
            if (!saveflag) {
                logger.error("保存数据库失败 uploadSampleDataTHRsp tSampThDataInfoHisEntity");
                SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataTHRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                return;
            }

            updsum = serverHandler.tSampBasiDataInfoService.updateSampValueByDevData(tSampBasiDataInfoEntity);
            if(updsum <= 0){
                logger.debug("插入新数据 uploadSampleDataTHRsp tSampBasiDataInfoEntity");
                saveflag = serverHandler.tSampBasiDataInfoService.save(tSampBasiDataInfoEntity);
                if (!saveflag) {
                    logger.error("保存数据库失败 uploadSampleDataTHRsp tSampBasiDataInfoEntity");
                    SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataTHRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                    return;
                }
            }

//            serverHandler.tBusiDevMonitorInfoService.updateMonitorByCode();
//            serverHandler.tBusiDevMonitorInfoService.save();

            SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataTHRsp", Constant.CMD_OK, null, q_obj, null, null, ctx);

        } catch (Exception ex) {
            logger.error("uploadSampleDataTH error： " + ex);
        }
//        "action": "uploadSampleDataTH",
//                "content": {
//            "THSampleData": {
//                "SampleDataBase": {
//                    "devSrc": "dev",
//                            "devId": "TP01MN2181221000042",
//                            "module": "TH",
//                            "time": "2019-08-22 08:17:58",
//                            "state": "normal",
//                            "ExceptionInfo": {
//                        "type": "1",
//                                "msg": "88%"
//                    }
//                },
//                "ambientTemp": "26.92",
//                        "relativeHumidity": "69.98",
//                        "pressure": ""
//            }
//        }
    }
    //终端上传可见光采样数据
    public static void uploadSampleDataCam(ServerHandler serverHandler,JSONObject q_obj,JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("uploadSampleDataCam");
        try {
            String msgId = obj.getString("msgId");
            TSampCameraDataInfoEntity tSampCameraDataInfoEntity = new TSampCameraDataInfoEntity();
            TSampBasiDataInfoEntity tSampBasiDataInfoEntity = new TSampBasiDataInfoEntity();

            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject CameraSampleDataobj = contentobj.getJSONObject("CameraSampleData");
            if (CameraSampleDataobj != null) {
                JSONObject SampleDataBaseobj = CameraSampleDataobj.getJSONObject("SampleDataBase");
                if (SampleDataBaseobj != null) {
                    logger.debug("SampleDataBaseobj");
                    String devSrc = SampleDataBaseobj.getString("devSrc");
                    String devId = SampleDataBaseobj.getString("devId");
                    String module = SampleDataBaseobj.getString("module");
                    String time = SampleDataBaseobj.getString("time");
                    String state = SampleDataBaseobj.getString("state");
                    JSONObject ExceptionInfoobj = SampleDataBaseobj.getJSONObject("ExceptionInfo");
                    if (ExceptionInfoobj != null) {
                        logger.debug("ExceptionInfoobj");
                        String type = ExceptionInfoobj.getString("type");
                        String msg = ExceptionInfoobj.getString("msg");
                        tSampBasiDataInfoEntity.setSampExceptionType(type);
                        tSampBasiDataInfoEntity.setSampExceptionMsg(msg);
                    }

                    time = dateTimeToString(time);

                    TBusiDevMonitorInfoEntity tBusiDevMonitorInfoEntity = new TBusiDevMonitorInfoEntity();
                    tBusiDevMonitorInfoEntity.setLastOpr((long)0);
                    tBusiDevMonitorInfoEntity.setLastTime(new Date());
                    tBusiDevMonitorInfoEntity.setDevCode(devId);
                    tBusiDevMonitorInfoEntity.setMonitorTime(time);

                    TBusiDevStatusInfoEntity tBusiDevStatusInfoEntity = new TBusiDevStatusInfoEntity();
                    if(state.equals("warning")){
                        tBusiDevStatusInfoEntity.setDevCode(devId);
                        tBusiDevStatusInfoEntity.setIsAlarm("1");
                        tBusiDevStatusInfoEntity.setLastOpr((long)0);
                        tBusiDevStatusInfoEntity.setLastTime(new Date());

                        int upsum = serverHandler.tBusiDevStatusInfoService.updateDevStatusInfoByCode(tBusiDevStatusInfoEntity);
                        if(upsum <= 0) {
                            logger.debug("插入新数据 uploadSampleDataIr tBusiDevStatusInfoEntity");
                            tBusiDevStatusInfoEntity.setCreateTime(new Date());
                            tBusiDevStatusInfoEntity.setCreateOpr((long)0);
                            tBusiDevStatusInfoEntity.setDevStatus("1");
                            tBusiDevStatusInfoEntity.setIsVaild("1");
//                            serverHandler.tBusiDevStatusInfoService.save(tBusiDevStatusInfoEntity);
                        }


                        tBusiDevMonitorInfoEntity.setVariableKind("00");
                        tBusiDevMonitorInfoEntity.setVariableDesc("可见光图片");
                        tBusiDevMonitorInfoEntity.setVariableStatus("1");

                        Date t = new Date();
                        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                        int resultal = serverHandler.tBusiSysAlarmInfoService.insertAlarmInfoBySystem(df.format(t), tBusiDevMonitorInfoEntity.getDevCode(), "00" + tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableDesc() + "告警");
                        logger.debug("可见光图片插入告警：编号[" + tBusiDevMonitorInfoEntity.getDevCode() + "]值：" + resultal);

                        String alarmType = "12";
                        AlarmSendingOutInfo alarmOutInfo = new AlarmSendingOutInfo();
                        alarmOutInfo.setDevCode(tBusiDevMonitorInfoEntity.getDevCode());
                        alarmOutInfo.setAlarmType(alarmType);
                        alarmOutInfo.setAlarmValue("2");
                        InitPointInfoDataConfService.cache2.put(tBusiDevMonitorInfoEntity.getDevCode() + tBusiDevMonitorInfoEntity.getVariableDesc(),alarmOutInfo);
                        logger.debug("外送可见光告警:设备编号["+tBusiDevMonitorInfoEntity.getDevCode()+"]"+tBusiDevMonitorInfoEntity.getVariableDesc()+"["+alarmType+"]登记告警2");
                        runClientSendData.runNettyClient(alarmType,"2",tBusiDevMonitorInfoEntity.getDevCode());
                    }else{
                        tBusiDevMonitorInfoEntity.setVariableKind("00");
                        tBusiDevMonitorInfoEntity.setVariableDesc("可见光图片");
                        tBusiDevMonitorInfoEntity.setVariableStatus("0");

                        AlarmSendingOutInfo alarmOutInfo = InitPointInfoDataConfService.cache2.get(tBusiDevMonitorInfoEntity.getDevCode() + tBusiDevMonitorInfoEntity.getVariableDesc());
                        if(alarmOutInfo != null){
                            if(alarmOutInfo.getAlarmValue().equals("2")){
                                logger.debug("外送可见光取消告警:设备编号["+tBusiDevMonitorInfoEntity.getDevCode()+"]"+tBusiDevMonitorInfoEntity.getVariableDesc()+"["+alarmOutInfo.getAlarmType()+"]取消告警1");
                                runClientSendData.runNettyClient(alarmOutInfo.getAlarmType(),"1",tBusiDevMonitorInfoEntity.getDevCode());

                                alarmOutInfo.setAlarmValue("1");
                                InitPointInfoDataConfService.cache2.put(tBusiDevMonitorInfoEntity.getDevCode() + tBusiDevMonitorInfoEntity.getVariableDesc(),alarmOutInfo);
                            }
                        }else{
                            logger.debug("可见光未找到告警记录无需外送告警");
                        }
                    }

                    int upsum = serverHandler.tBusiDevMonitorInfoService.updateMonitorByCodeKindDesc(tBusiDevMonitorInfoEntity);
                    if(upsum <= 0) {
                        logger.debug("更新可见光图片状态失败 updateMonitorByCodeKindDesc");
                        tBusiDevMonitorInfoEntity.setCreateTime(new Date());
                        tBusiDevMonitorInfoEntity.setCreateOpr((long)0);
                        tBusiDevMonitorInfoEntity.setVariableValue("0");
                        tBusiDevMonitorInfoEntity.setVariableValue2("0");
                        tBusiDevMonitorInfoEntity.setVariableValue3("0");
                        try {
                            String codeStr = getVariableCodeByName(tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableKind(), serverHandler);
                            if (codeStr != null && codeStr != "") {
                                tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                            } else {
                                tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                                logger.debug("code值未配置：name:" + tBusiDevMonitorInfoEntity.getVariableDesc() + " kind:" + tBusiDevMonitorInfoEntity.getVariableKind());
                            }
                            serverHandler.tBusiDevMonitorInfoService.save(tBusiDevMonitorInfoEntity);
                        }catch(Exception e){
                            logger.debug("monitor 添加失败:可见光图片");
                        }
                    }

                    tSampBasiDataInfoEntity.setDevSrc(devSrc);
                    tSampBasiDataInfoEntity.setDevId(devId);
                    tSampBasiDataInfoEntity.setModuleName(module);
                    tSampBasiDataInfoEntity.setSampTime(time);
                    tSampBasiDataInfoEntity.setSampState(state);
                    tSampBasiDataInfoEntity.setCreateTime(new Date());
                    tSampBasiDataInfoEntity.setLastTime(new Date());

                    tSampCameraDataInfoEntity.setDevId(devId);
                }

                String fileCamImg = CameraSampleDataobj.getString("fileCamImg");
                String fileCamSobelImg = CameraSampleDataobj.getString("fileSobelImg");
                String fileCamIdImg = CameraSampleDataobj.getString("fileCamIdImg");
                String fileCamVideo = CameraSampleDataobj.getString("fileCamVideo");

                tSampCameraDataInfoEntity.setFileCamImg(fileCamImg);
                tSampCameraDataInfoEntity.setFileSobeImg(fileCamSobelImg);
                tSampCameraDataInfoEntity.setFileCamIdImg(fileCamIdImg);
                tSampCameraDataInfoEntity.setFileCamVideo(fileCamVideo);
                tSampCameraDataInfoEntity.setCreateTime(new Date());
                tSampCameraDataInfoEntity.setLastTime(new Date());
            }
            //入库或更新操作
            boolean saveflag;
            int updsum = serverHandler.tSampCameraDataInfoService.updateByDevId(tSampCameraDataInfoEntity);
            if(updsum <= 0) {
                logger.debug("插入新数据 uploadSampleDataCamRsp tSampCameraDataInfoEntity");
                saveflag = serverHandler.tSampCameraDataInfoService.save(tSampCameraDataInfoEntity);
                if (!saveflag) {
                    logger.error("保存数据库失败 uploadSampleDataCamRsp tSampCameraDataInfoEntity");
                    SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataCamRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                    return;
                }
            }

            TSampCameraDataInfoHisEntity tSampCameraDataInfoHisEntity = new TSampCameraDataInfoHisEntity();
            BeanUtils.copyProperties(tSampCameraDataInfoEntity, tSampCameraDataInfoHisEntity);
            saveflag = serverHandler.tSampCameraDataInfoHisService.save(tSampCameraDataInfoHisEntity);
            if (!saveflag) {
                logger.error("保存数据库失败 uploadSampleDataCamRsp tSampCameraDataInfoHisEntity");
                SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataCamRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                return;
            }

            updsum = serverHandler.tSampBasiDataInfoService.updateSampValueByDevData(tSampBasiDataInfoEntity);
            if(updsum <= 0) {
                logger.debug("插入新数据 uploadSampleDataCamRsp tSampBasiDataInfoEntity");
                saveflag = serverHandler.tSampBasiDataInfoService.save(tSampBasiDataInfoEntity);
                if (!saveflag) {
                    logger.error("保存数据库失败 uploadSampleDataCamRsp tSampBasiDataInfoEntity");
                    SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataCamRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                    return;
                }
            }

            SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataCamRsp", Constant.CMD_OK, null, q_obj, null, null, ctx);

        } catch (Exception ex) {
            logger.error("uploadSampleDataCam error： " + ex);
        }
//        "action": "uploadSampleDataCam",
//                "msgId": "",
//                "content": {
//            "CameraSampleData": {
//                "SampleDataBase": {
//                    "devSrc": "dev",
//                            "devId": "TP01MN2181221000042",
//                            "module": "Camera",
//                            "time": "2019-08-22 08:17:58",
//                            "state": "normal",
//                            "ExceptionInfo": {
//                        "type": "1",
//                                "msg": "88%"
//                    }
//                },
//                "fileCamImg": "20190928_155226.jpg",
//                        "fileCamSobelImg": "20190928_155226_sobel.jpg",
//                "fileCamIdImg": "20190928_155226_id.jpg",
//                        "fileCamVideo": "20190928_155226_video.mp4"
//            }
//        }
    }

    public  static String  getVariableCodeByName(String varName,String kind,ServerHandler serverHandler){
        String ret ="";
        TInfoVariableInfoEntity tInfoVariableInfoEntity = new TInfoVariableInfoEntity();
        tInfoVariableInfoEntity.setVariableKind(kind);
        List<TInfoVariableInfoEntity> VariableList=serverHandler.tInfoVariableInfoService.queryVariableByCondition(tInfoVariableInfoEntity);
        for(TInfoVariableInfoEntity o : VariableList){
            if(o.getVariableName().equals(varName))
            {
                ret=String.valueOf(o.getVariableId());
            }
        }
        return ret;
    }

    //终端上传红外采样数据
    public static void uploadSampleDataIr(ServerHandler serverHandler,JSONObject q_obj,JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("uploadSampleDataIr");
        try {
            boolean saveflag;
            String msgId = obj.getString("msgId");
            TSampIrDataInfoEntity tSampIrDataInfoEntity = new TSampIrDataInfoEntity();
            TSampIrSensorTempEntity tSampIrSensorTempEntity = new TSampIrSensorTempEntity();
            TSampBasiDataInfoEntity tSampBasiDataInfoEntity = new TSampBasiDataInfoEntity();

            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject IrSampleDataobj = contentobj.getJSONObject("IrSampleData");
            if (IrSampleDataobj != null) {
                JSONObject SampleDataBaseobj = IrSampleDataobj.getJSONObject("SampleDataBase");
                if (SampleDataBaseobj != null) {
                    String devSrc = SampleDataBaseobj.getString("devSrc");
                    String devId = SampleDataBaseobj.getString("devId");
                    String module = SampleDataBaseobj.getString("module");
                    String time = SampleDataBaseobj.getString("time");
                    String state = SampleDataBaseobj.getString("state");
                    JSONObject ExceptionInfoobj = SampleDataBaseobj.getJSONObject("ExceptionInfo");
                    if (ExceptionInfoobj != null) {
                        String type = ExceptionInfoobj.getString("type");
                        String msg = ExceptionInfoobj.getString("msg");
                        tSampBasiDataInfoEntity.setSampExceptionType(type);
                        tSampBasiDataInfoEntity.setSampExceptionMsg(msg);
                    }

                    time = dateTimeToString(time);

                    TBusiDevMonitorInfoEntity tBusiDevMonitorInfoEntity = new TBusiDevMonitorInfoEntity();
                    tBusiDevMonitorInfoEntity.setLastOpr((long)0);
                    tBusiDevMonitorInfoEntity.setLastTime(new Date());
                    tBusiDevMonitorInfoEntity.setDevCode(devId);
                    tBusiDevMonitorInfoEntity.setMonitorTime(time);

                    TBusiDevStatusInfoEntity tBusiDevStatusInfoEntity = new TBusiDevStatusInfoEntity();
                    if(state.equals("warning")){
                        tBusiDevStatusInfoEntity.setDevCode(devId);
                        tBusiDevStatusInfoEntity.setIsAlarm("1");
                        tBusiDevStatusInfoEntity.setLastOpr((long)0);
                        tBusiDevStatusInfoEntity.setLastTime(new Date());

                        int upsum = serverHandler.tBusiDevStatusInfoService.updateDevStatusInfoByCode(tBusiDevStatusInfoEntity);
                        if(upsum <= 0) {
                            logger.debug("插入新数据 uploadSampleDataIr tBusiDevStatusInfoEntity");
                            tBusiDevStatusInfoEntity.setCreateTime(new Date());
                            tBusiDevStatusInfoEntity.setCreateOpr((long)0);
                            tBusiDevStatusInfoEntity.setDevStatus("1");
                            tBusiDevStatusInfoEntity.setIsVaild("1");
//                            serverHandler.tBusiDevStatusInfoService.save(tBusiDevStatusInfoEntity);
                        }


                        tBusiDevMonitorInfoEntity.setVariableKind("00");
                        tBusiDevMonitorInfoEntity.setVariableDesc("红外热像");
                        tBusiDevMonitorInfoEntity.setVariableStatus("1");

                        Date t = new Date();
                        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                        int resultal = serverHandler.tBusiSysAlarmInfoService.insertAlarmInfoBySystem(df.format(t), tBusiDevMonitorInfoEntity.getDevCode(), "00" + tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableDesc() + "告警");
                        logger.debug("红外热像插入告警：编号[" + tBusiDevMonitorInfoEntity.getDevCode() + "]值：" + resultal);
                        String alarmType = "10";
                        AlarmSendingOutInfo alarmOutInfo = new AlarmSendingOutInfo();
                        alarmOutInfo.setDevCode(tBusiDevMonitorInfoEntity.getDevCode());
                        alarmOutInfo.setAlarmType(alarmType);
                        alarmOutInfo.setAlarmValue("2");
                        InitPointInfoDataConfService.cache2.put(tBusiDevMonitorInfoEntity.getDevCode() + tBusiDevMonitorInfoEntity.getVariableDesc(),alarmOutInfo);
                        logger.debug("外送红外热像告警:设备编号["+tBusiDevMonitorInfoEntity.getDevCode()+"]"+tBusiDevMonitorInfoEntity.getVariableDesc()+"["+alarmType+"]登记告警2");
                        runClientSendData.runNettyClient(alarmType,"2",tBusiDevMonitorInfoEntity.getDevCode());

                    }else{
                        tBusiDevMonitorInfoEntity.setVariableKind("00");
                        tBusiDevMonitorInfoEntity.setVariableDesc("红外热像");
                        tBusiDevMonitorInfoEntity.setVariableStatus("0");

                        AlarmSendingOutInfo alarmOutInfo = InitPointInfoDataConfService.cache2.get(tBusiDevMonitorInfoEntity.getDevCode() + tBusiDevMonitorInfoEntity.getVariableDesc());
                        if(alarmOutInfo != null){
                            if(alarmOutInfo.getAlarmValue().equals("2")){
                                logger.debug("外送红外热像取消告警:设备编号["+tBusiDevMonitorInfoEntity.getDevCode()+"]"+tBusiDevMonitorInfoEntity.getVariableDesc()+"["+alarmOutInfo.getAlarmType()+"]取消告警1");
                                runClientSendData.runNettyClient(alarmOutInfo.getAlarmType(),"1",tBusiDevMonitorInfoEntity.getDevCode());

                                alarmOutInfo.setAlarmValue("1");
                                InitPointInfoDataConfService.cache2.put(tBusiDevMonitorInfoEntity.getDevCode() + tBusiDevMonitorInfoEntity.getVariableDesc(),alarmOutInfo);
                            }
                        }else{
                            logger.debug("红外热像未找到告警记录无需外送告警");
                        }
                    }

                    int upsum = serverHandler.tBusiDevMonitorInfoService.updateMonitorByCodeKindDesc(tBusiDevMonitorInfoEntity);
                    if(upsum <= 0) {
                        logger.debug("更新红外热像状态失败 updateMonitorByCodeKindDesc-开始插入");
                        tBusiDevMonitorInfoEntity.setCreateTime(new Date());
                        tBusiDevMonitorInfoEntity.setCreateOpr((long)0);
                        tBusiDevMonitorInfoEntity.setVariableValue("0");
                        tBusiDevMonitorInfoEntity.setVariableValue2("0");
                        tBusiDevMonitorInfoEntity.setVariableValue3("0");
                        try {
                            String codeStr = getVariableCodeByName(tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableKind(), serverHandler);
                            if (codeStr != null && codeStr != "") {
                                tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                            } else {
                                tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                                logger.debug("code值未配置：name:" + tBusiDevMonitorInfoEntity.getVariableDesc() + " kind:" + tBusiDevMonitorInfoEntity.getVariableKind());
                            }

                            serverHandler.tBusiDevMonitorInfoService.save(tBusiDevMonitorInfoEntity);
                        }catch(Exception e){
                            logger.debug("monitor 添加失败:红外热像");
                        }
                    }

                    tSampBasiDataInfoEntity.setDevSrc(devSrc);
                    tSampBasiDataInfoEntity.setDevId(devId);
                    tSampBasiDataInfoEntity.setModuleName(module);
                    tSampBasiDataInfoEntity.setSampTime(time);
                    tSampBasiDataInfoEntity.setSampState(state);
                    tSampBasiDataInfoEntity.setCreateTime(new Date());
                    tSampBasiDataInfoEntity.setLastTime(new Date());

                    tSampIrDataInfoEntity.setDevId(devId);
                    JSONArray IrTemparray = IrSampleDataobj.getJSONArray("IrTemp");
                    if (IrTemparray != null) {
                        for (int i = 0; i < IrTemparray.size(); i++) {
                            JSONObject IrTempobj = IrTemparray.getJSONObject(i);
                            String name = IrTempobj.getString("name");
                            String maxTemp = IrTempobj.getString("maxTemp");
                            String minTemp = IrTempobj.getString("minTemp");

                            tSampIrSensorTempEntity.setDevId(devId);
                            tSampIrSensorTempEntity.setAreaName(name);
                            tSampIrSensorTempEntity.setAreaMaxTemp(maxTemp);
                            tSampIrSensorTempEntity.setAreaMinTemp(minTemp);

                            tSampIrSensorTempEntity.setCreateTime(new Date());
                            tSampIrSensorTempEntity.setLastTime(new Date());


                            int updnum = serverHandler.tSampIrSensorTempService.updateSampValueByDevArea(tSampIrSensorTempEntity);
                            if(updnum <= 0) {
                                logger.debug("插入新数据 uploadSampleDataIrRsp tSampIrSensorTempEntity");
                                saveflag = serverHandler.tSampIrSensorTempService.save(tSampIrSensorTempEntity);
                                if (!saveflag) {
                                    logger.error("保存数据库失败 uploadSampleDataIrRsp tSampIrSensorTempEntity");
                                    SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataIrRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                                    return;
                                }
                            }

                            TSampIrSensorTempHisEntity tSampIrSensorTempHisEntity = new TSampIrSensorTempHisEntity();
                            BeanUtils.copyProperties(tSampIrSensorTempEntity, tSampIrSensorTempHisEntity);
                            saveflag = serverHandler.tSampIrSensorTempHisService.save(tSampIrSensorTempHisEntity);
                            if (!saveflag) {
                                logger.error("保存数据库失败 uploadSampleDataIrRsp tSampIrSensorTempHisEntity");
                                SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataIrRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                                return;
                            }
                        }
                    }
                }

                String irModType = IrSampleDataobj.getString("irModType");
                String fileTemp = IrSampleDataobj.getString("fileTemp");
                String fileIrImg = IrSampleDataobj.getString("fileIrImg");
                String fileOvTemp = IrSampleDataobj.getString("fileOvTemp");
                String fileOvImg = IrSampleDataobj.getString("fileOvImg");

                tSampIrDataInfoEntity.setIrModType(irModType);
                tSampIrDataInfoEntity.setFileTemp(fileTemp);
                tSampIrDataInfoEntity.setFileIrImg(fileIrImg);
                tSampIrDataInfoEntity.setFileOvTemp(fileOvTemp);
                tSampIrDataInfoEntity.setFileOvImg(fileOvImg);
                tSampIrDataInfoEntity.setCreateTime(new Date());
                tSampIrDataInfoEntity.setLastTime(new Date());
            }
            //入库或更新操作
            int updsum = serverHandler.tSampIrDataInfoService.updateByDevId(tSampIrDataInfoEntity);
            if(updsum <= 0) {
                logger.debug("插入新数据 uploadSampleDataIrRsp tSampIrDataInfoEntity");
                saveflag = serverHandler.tSampIrDataInfoService.save(tSampIrDataInfoEntity);
                if (!saveflag) {
                    logger.error("保存数据库失败 uploadSampleDataIrRsp tSampIrDataInfoEntity");
                    SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataIrRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                    return;
                }
            }

            TSampIrDataInfoHisEntity tSampIrDataInfoHisEntity = new TSampIrDataInfoHisEntity();
            BeanUtils.copyProperties(tSampIrDataInfoEntity, tSampIrDataInfoHisEntity);
            saveflag = serverHandler.tSampIrDataInfoHisService.save(tSampIrDataInfoHisEntity);
            if (!saveflag) {
                logger.error("保存数据库失败 uploadSampleDataIrRsp tSampIrDataInfoHisEntity");
                SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataIrRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                return;
            }

            updsum = serverHandler.tSampBasiDataInfoService.updateSampValueByDevData(tSampBasiDataInfoEntity);
            if(updsum <= 0) {
                logger.debug("插入新数据 uploadSampleDataIrRsp tSampBasiDataInfoEntity");
                saveflag = serverHandler.tSampBasiDataInfoService.save(tSampBasiDataInfoEntity);
                if (!saveflag) {
                    logger.error("保存数据库失败 uploadSampleDataIrRsp tSampBasiDataInfoEntity");
                    SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataIrRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                    return;
                }
            }

            SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataIrRsp", Constant.CMD_OK, null, q_obj, null, null, ctx);

        } catch (Exception ex) {
            logger.error("uploadSampleDataIr error： " + ex);
        }
//        "action": "uploadSampleDataIr",
//                "msgId": "",
//                "content": {
//            "IrSampleData": {
//                "SampleDataBase": {
//                    "devSrc": "dev",
//                            "devId": "TP01MN2181221000042",
//                            "module": "IR",
//                            "time": "2019-08-22 08:17:58",
//                            "state": "normal",
//                            "ExceptionInfo": {
//                        "type": "1",
//                                "msg": "88%"
//                    }
//                },
//                "IrTemp": [
//                {
//                    "name": "ALL",
//                        "maxTemp": "33.76",
//                        "minTemp": "19.09"
//                },
//                {
//                    "name": "A",
//                        "maxTemp": "27.1",
//                        "minTemp": "19.95"
//                },
//                {
//                    "name": "B",
//                        "maxTemp": "33.0",
//                        "minTemp": "20.08"
//                },
//                {
//                    "name": "C",
//                        "maxTemp": "33.76",
//                        "minTemp": "19.09"
//                }
//],
//                "irModType": "thermapp",
//                        "fileTemp": "20190928_155227_854_temp.txt",
//                        "fileIrImg": "20190928_155224_357_therm.png",
//                        "fileOvTemp": "20190928_155227_854_ov_temp.txt",
//                        "fileOvImg": "20190928_155228_938_ov.png"
//            }
//        }
    }

    //终端上传特高频局放采样数据
    public static void uploadSampleDataJf(ServerHandler serverHandler,JSONObject q_obj,JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("uploadSampleDataJf");
        try {
            String msgId = obj.getString("msgId");
            TSampJfDataInfoEntity tSampJfDataInfoEntity = new TSampJfDataInfoEntity();
            TSampBasiDataInfoEntity tSampBasiDataInfoEntity = new TSampBasiDataInfoEntity();
            TBusiDevStatusInfoEntity tBusiDevStatusInfoEntity = new TBusiDevStatusInfoEntity();

            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject JfSampleDataobj = contentobj.getJSONObject("JfSampleData");
            if (JfSampleDataobj != null) {
                JSONObject SampleDataBase = JfSampleDataobj.getJSONObject("SampleDataBase");
                String devSrc = SampleDataBase.getString("devSrc");
                String devId = SampleDataBase.getString("devId");
                String module = SampleDataBase.getString("module");
                String time = SampleDataBase.getString("time");
                String state = SampleDataBase.getString("state");
                JSONObject ExceptionInfoobj = SampleDataBase.getJSONObject("ExceptionInfo");
                if (ExceptionInfoobj != null) {
                    String type = ExceptionInfoobj.getString("type");
                    String msg = ExceptionInfoobj.getString("msg");

                    tSampBasiDataInfoEntity.setSampExceptionType(type);
                    tSampBasiDataInfoEntity.setSampExceptionMsg(msg);
                }

                time = dateTimeToString(time);

                TBusiDevMonitorInfoEntity tBusiDevMonitorInfoEntity = new TBusiDevMonitorInfoEntity();
                tBusiDevMonitorInfoEntity.setLastOpr((long)0);
                tBusiDevMonitorInfoEntity.setLastTime(new Date());
                tBusiDevMonitorInfoEntity.setDevCode(devId);
                tBusiDevMonitorInfoEntity.setMonitorTime(time);

                if(state.equals("warning")){
                    tBusiDevStatusInfoEntity.setDevCode(devId);
                    tBusiDevStatusInfoEntity.setIsAlarm("1");
                    tBusiDevStatusInfoEntity.setLastOpr((long)0);
                    tBusiDevStatusInfoEntity.setLastTime(new Date());

                    int upsum = serverHandler.tBusiDevStatusInfoService.updateDevStatusInfoByCode(tBusiDevStatusInfoEntity);
                    if(upsum <= 0) {
                        logger.debug("插入新数据 uploadSampleDataJf tBusiDevStatusInfoEntity");
                        tBusiDevStatusInfoEntity.setCreateTime(new Date());
                        tBusiDevStatusInfoEntity.setCreateOpr((long)0);
                        tBusiDevStatusInfoEntity.setDevStatus("1");
                        tBusiDevStatusInfoEntity.setIsVaild("1");
//                        serverHandler.tBusiDevStatusInfoService.save(tBusiDevStatusInfoEntity);
                    }


                    tBusiDevMonitorInfoEntity.setVariableKind("00");
                    tBusiDevMonitorInfoEntity.setVariableDesc("局放");
                    tBusiDevMonitorInfoEntity.setVariableStatus("1");

                    Date t = new Date();
                    SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                    int resultal = serverHandler.tBusiSysAlarmInfoService.insertAlarmInfoBySystem(df.format(t), tBusiDevMonitorInfoEntity.getDevCode(), "00" + tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableDesc() + "告警");
                    logger.debug("特高频局放插入告警：编号[" + tBusiDevMonitorInfoEntity.getDevCode() + "]值：" + resultal);

                    String alarmType = "11";
                    AlarmSendingOutInfo alarmOutInfo = new AlarmSendingOutInfo();
                    alarmOutInfo.setDevCode(tBusiDevMonitorInfoEntity.getDevCode());
                    alarmOutInfo.setAlarmType(alarmType);
                    alarmOutInfo.setAlarmValue("2");
                    InitPointInfoDataConfService.cache2.put(tBusiDevMonitorInfoEntity.getDevCode() + tBusiDevMonitorInfoEntity.getVariableDesc(),alarmOutInfo);
                    logger.debug("外送特高频局放红外热像告警:设备编号["+tBusiDevMonitorInfoEntity.getDevCode()+"]"+tBusiDevMonitorInfoEntity.getVariableDesc()+"["+alarmType+"]登记告警2");
                    runClientSendData.runNettyClient(alarmType,"2",tBusiDevMonitorInfoEntity.getDevCode());

                }else{
                    tBusiDevMonitorInfoEntity.setVariableKind("00");
                    tBusiDevMonitorInfoEntity.setVariableDesc("局放");
                    tBusiDevMonitorInfoEntity.setVariableStatus("0");

                    AlarmSendingOutInfo alarmOutInfo = InitPointInfoDataConfService.cache2.get(tBusiDevMonitorInfoEntity.getDevCode() + tBusiDevMonitorInfoEntity.getVariableDesc());
                    if(alarmOutInfo != null){
                        if(alarmOutInfo.getAlarmValue().equals("2")){
                            logger.debug("外送特高频局放取消告警:设备编号["+tBusiDevMonitorInfoEntity.getDevCode()+"]"+tBusiDevMonitorInfoEntity.getVariableDesc()+"["+alarmOutInfo.getAlarmType()+"]取消告警1");
                            runClientSendData.runNettyClient(alarmOutInfo.getAlarmType(),"1",tBusiDevMonitorInfoEntity.getDevCode());

                            alarmOutInfo.setAlarmValue("1");
                            InitPointInfoDataConfService.cache2.put(tBusiDevMonitorInfoEntity.getDevCode() + tBusiDevMonitorInfoEntity.getVariableDesc(),alarmOutInfo);
                        }
                    }else{
                        logger.debug("特高频局放未找到告警记录无需外送告警");
                    }
                }

                int upsum = serverHandler.tBusiDevMonitorInfoService.updateMonitorByCodeKindDesc(tBusiDevMonitorInfoEntity);
                if(upsum <= 0) {
                    logger.debug("更新局放特高频状态失败 updateMonitorByCodeKindDesc - 插入");

                    tBusiDevMonitorInfoEntity.setCreateTime(new Date());
                    tBusiDevMonitorInfoEntity.setCreateOpr((long)0);
                    tBusiDevMonitorInfoEntity.setVariableValue("0");
                    tBusiDevMonitorInfoEntity.setVariableValue2("0");
                    tBusiDevMonitorInfoEntity.setVariableValue3("0");
                    try {
                        String codeStr = getVariableCodeByName(tBusiDevMonitorInfoEntity.getVariableDesc(), tBusiDevMonitorInfoEntity.getVariableKind(), serverHandler);
                        if (codeStr != null && codeStr != "") {
                            tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                        } else {
                            tBusiDevMonitorInfoEntity.setVariableCode(codeStr);
                            logger.debug("code值未配置：name:" + tBusiDevMonitorInfoEntity.getVariableDesc() + " kind:" + tBusiDevMonitorInfoEntity.getVariableKind());
                        }

                        serverHandler.tBusiDevMonitorInfoService.save(tBusiDevMonitorInfoEntity);
                    }catch(Exception e){
                        logger.debug("monitor 添加失败:局放");
                    }
                }

                tSampBasiDataInfoEntity.setDevSrc(devSrc);
                tSampBasiDataInfoEntity.setDevId(devId);
                tSampBasiDataInfoEntity.setModuleName(module);
                tSampBasiDataInfoEntity.setSampTime(time);
                tSampBasiDataInfoEntity.setSampState(state);
                tSampBasiDataInfoEntity.setCreateTime(new Date());
                tSampBasiDataInfoEntity.setLastTime(new Date());

                tSampJfDataInfoEntity.setDevId(devId);
            }

            String AvDsch = JfSampleDataobj.getString("AvDsch");
            String MaxDsch = JfSampleDataobj.getString("MaxDsch");
            String DschCnt = JfSampleDataobj.getString("DschCnt");
            String DschPhase = JfSampleDataobj.getString("DschPhase");
            String filePrpd = JfSampleDataobj.getString("filePrpd");
            String filePrps = JfSampleDataobj.getString("filePrps");

            tSampJfDataInfoEntity.setAvDsch(AvDsch);
            tSampJfDataInfoEntity.setMaxDsch(MaxDsch);
            tSampJfDataInfoEntity.setDschCnt(DschCnt);
            tSampJfDataInfoEntity.setDschPhase(DschPhase);
            tSampJfDataInfoEntity.setFilePrpd(filePrpd);
            tSampJfDataInfoEntity.setFilePrps(filePrps);
            //入库或更新操作

            boolean saveflag;
            logger.debug("保存数据库------");
            int updsum = serverHandler.tSampBasiDataInfoService.updateSampValueByDevData(tSampBasiDataInfoEntity);
            if(updsum <= 0) {
                logger.debug("插入新数据 uploadSampleDataJfRsp tSampBasiDataInfoEntity");
                saveflag = serverHandler.tSampBasiDataInfoService.save(tSampBasiDataInfoEntity);
                if (!saveflag) {
                    logger.error("保存数据库失败 uploadSampleDataJfRsp tSampBasiDataInfoEntity");
                    SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataJfRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                    return;
                }
            }
            tSampJfDataInfoEntity.setLastTime(new Date());
            updsum = serverHandler.tSampJfDataInfoService.updateByDevId(tSampJfDataInfoEntity);
            tSampJfDataInfoEntity.setCreateTime(new Date());
            if(updsum <= 0) {
                logger.debug("插入新数据 uploadSampleDataJfRsp tSampJfDataInfoEntity");
                saveflag = serverHandler.tSampJfDataInfoService.save(tSampJfDataInfoEntity);
                if (!saveflag) {
                    logger.error("保存数据库失败 uploadSampleDataJfRsp tSampJfDataInfoEntity");
                    SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataJfRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                    return;
                }
                logger.debug("保存数据库完成");
            }

            TSampJfDataInfoHisEntity tSampJfDataInfoHisEntity = new TSampJfDataInfoHisEntity();
            BeanUtils.copyProperties(tSampJfDataInfoEntity, tSampJfDataInfoHisEntity);
            saveflag = serverHandler.tSampJfDataInfoHisService.save(tSampJfDataInfoHisEntity);
            if (!saveflag) {
                logger.error("保存数据库失败 uploadSampleDataJfRsp tSampJfDataInfoHisEntity");
                SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataJfRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                return;
            }

            SendMsgRes.sendJsonResMsgOKorERROR("uploadSampleDataJfRsp", Constant.CMD_OK, null, q_obj, null, null, ctx);

        } catch (Exception ex) {
            logger.error("uploadSampleDataJf error： " + ex);
        }
//        "action": "uploadSampleDataJf",
//                "msgId": "",
//                "content": {
//            "JfSampleData": {
//                "SampleDataBase": {
//                    "devSrc": "ied",
//                            "devId": "SU10AX123450007",
//                            "module": "UHF",
//                            "time": "2019-08-22 08:17:58",
//                            "state": "normal",
//                            "ExceptionInfo": {
//                        "type": "1",
//                                "msg": "88%"
//                    }
//                },
//                "AvDsch": "196",
//                        "MaxDsch": "687",
//                        "DschCnt": "1156",
//                        "DschPhase": "258",
//                        "filePrpd": "20190629_100013_511_prpd.png",
//                        "filePrps": "20190629_160616_088_prps.png"
//            }
//        }
    }

    //终端上传采样数据（重症监护协议）
    public static void uploadIcuSampleData(ServerHandler serverHandler,JSONObject q_obj,JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("uploadIcuSampleData");
        try {
            String msgId = obj.getString("msgId");
            JSONObject contentobj = obj.getJSONObject("content");
            JSONArray ComFilearray = contentobj.getJSONArray("ComFile");
            int upsum = 0;
            boolean saveflag;
            if(ComFilearray!=null) {
                for (int i = 0; i < ComFilearray.size(); i++) {
                    JSONObject ComFileobj = ComFilearray.getJSONObject(i);
                    String devSrc = ComFileobj.getString("devSrc");
                    String purpose = ComFileobj.getString("purpose");
                    String devId = ComFileobj.getString("devId");
                    String fileName = ComFileobj.getString("fileName");
                    String fileType = ComFileobj.getString("fileType");
                    String fileData = ComFileobj.getString("fileData");
                    //入库或其他操作
                    TFileInfoEntity tFileInfoEntity = new TFileInfoEntity();
                    tFileInfoEntity.setDevId(devId);
                    tFileInfoEntity.setDevSrc(devSrc);
                    tFileInfoEntity.setPurpose(purpose);
                    tFileInfoEntity.setFileName(fileName);
                    tFileInfoEntity.setFileType(fileType);
                    tFileInfoEntity.setFileData(fileData);
                    tFileInfoEntity.setCreateOpr((long)0);
                    tFileInfoEntity.setLastOpr((long)0);
                    tFileInfoEntity.setCreateTime(new Date());
                    tFileInfoEntity.setLastTime(new Date());
                    upsum = serverHandler.tFileInfoService.updateByDevId(tFileInfoEntity);
                    logger.debug("updateByDevId(tFileInfoEntity)更新数据库影响数目：" + upsum);
                    if(upsum <= 0) {
                        logger.debug("插入新数据 ：" + devId);
                        saveflag = serverHandler.tFileInfoService.save(tFileInfoEntity);
                        if (!saveflag) {
                            logger.error("保存数据库失败 uploadIcuSampleDataRsp tFileInfoEntity");
                            SendMsgRes.sendJsonResMsgOKorERROR("uploadIcuSampleDataRsp", Constant.CMD_ERROR, null, obj, null, null, ctx);
                            return;
                        }
                    }
                }
            }
//            String content = obj.getString("msg");
//            logger.debug(result + msg);
            SendMsgRes.sendJsonResMsgOKorERROR("uploadIcuSampleDataRsp", Constant.CMD_OK, null, q_obj, null, null, ctx);
        } catch (Exception ex) {
            logger.error("uploadIcuSampleData error： " + ex);
        }
    }

    public static String dateTimeToString(String time){
        try {
            logger.debug("SampleDataBase-date-time["+time+"]");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = null;
            // 注意格式需要与上面一致，不然会出现异常
            date = sdf.parse(time);
            logger.debug("SampleDataBase-date["+date+"]");
            SimpleDateFormat dff = new SimpleDateFormat("yyyyMMddHHmmss");
            time = dff.format(date);
            logger.debug("SampleDataBase-string-time["+time+"]");
        }catch(ParseException e){
            logger.debug("dateTimeToString error:" + e);
        }

        return time;
    }
//        {
//            "action": "uploadIcuSampleData",
//            "msgId":"",
//                "content": {
//            "ComFile": [
//            {
//                "devSrc": "dev",
//                    "purpose": "sampleIcuData",
//                    "devId": "MP01MN1190601000207",
//                    "fileName": "MNT2000_06Mxxxxx_20190414120006651.dat",
//                    "fileType": "dat",
//                    "fileData": "xxxxxxxYYYYzzzzzsssssDDDDcplshaljljajlga"
//            },
//            {
//                "devSrc": "ied",
//                    "purpose": "sampleIcuData",
//                    "devId": "SU10ABC9988765",
//                    "fileName": "MNT2000_06Mxxxxx_20190414120006651.dat",
//                    "fileType": "dat",
//                    "fileData": "xxxxxxxYYYYzzzzzsssssDDDDcplshaljljajlga"
//            }
//]
//        }
//        }

    //应答
//        {
//            "action":"uploadDataRsp",
//                "msgId":"",
//                "result":"ok",
//                "msg":"success"
//        }
//        或者
//        {
//            "action":"uploadDataRsp",
//                "msgId":"",
//                "result":"error",
//                "msg":"文件解析错误"
//        }
}

